home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / symtab.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  82KB  |  2,976 lines

  1. /* Symbol table lookup for the GNU debugger, GDB.
  2.    Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include "defs.h"
  22. #include "symtab.h"
  23. #include "param.h"
  24. #include "gdbcore.h"
  25. #include "frame.h"
  26. #include "target.h"
  27. #include "value.h"
  28. #include "symfile.h"
  29. #include "gdbcmd.h"
  30. #include "regex.h"
  31. #include "language.h"
  32.  
  33. #include <obstack.h>
  34. #include <assert.h>
  35.  
  36. #include <sys/types.h>
  37. #include <fcntl.h>
  38. #include <string.h>
  39. #include <sys/stat.h>
  40.  
  41. extern char *getenv ();
  42.  
  43. extern char *cplus_demangle ();
  44. extern struct value *value_of_this ();
  45. extern void break_command ();
  46. extern void select_source_symtab ();
  47.  
  48. /* Functions this file defines */
  49. static int find_line_common ();
  50. struct partial_symtab *lookup_partial_symtab ();
  51. static struct partial_symbol *lookup_partial_symbol ();
  52. static struct partial_symbol *lookup_demangled_partial_symbol ();
  53. static struct symbol *lookup_demangled_block_symbol ();
  54.  
  55. /* The single non-language-specific builtin type */
  56. struct type *builtin_type_error;
  57.  
  58. /* Block in which the most recently searched-for symbol was found.
  59.    Might be better to make this a parameter to lookup_symbol and 
  60.    value_of_this. */
  61. struct block *block_found;
  62.  
  63. char no_symtab_msg[] = "No symbol table is loaded.  Use the \"file\" command.";
  64.  
  65. /* Check for a symtab of a specific name; first in symtabs, then in
  66.    psymtabs.  *If* there is no '/' in the name, a match after a '/'
  67.    in the symtab filename will also work.  */
  68.  
  69. static struct symtab *
  70. lookup_symtab_1 (name)
  71.      char *name;
  72. {
  73.   register struct symtab *s;
  74.   register struct partial_symtab *ps;
  75.   register char *slash = strchr (name, '/');
  76.   register int len = strlen (name);
  77.  
  78.   for (s = symtab_list; s; s = s->next)
  79.     if (!strcmp (name, s->filename))
  80.       return s;
  81.  
  82.   for (ps = partial_symtab_list; ps; ps = ps->next)
  83.     if (!strcmp (name, ps->filename))
  84.       {
  85.     if (ps->readin)
  86.       error ("Internal: readin pst found when no symtab found.");
  87.     return PSYMTAB_TO_SYMTAB (ps);
  88.       }
  89.  
  90.   if (!slash)
  91.     {
  92.       for (s = symtab_list; s; s = s->next)
  93.     {
  94.       int l = strlen (s->filename);
  95.  
  96.       if (s->filename[l - len -1] == '/'
  97.           && !strcmp (s->filename + l - len, name))
  98.         return s;
  99.     }
  100.  
  101.       for (ps = partial_symtab_list; ps; ps = ps->next)
  102.     {
  103.       int l = strlen (ps->filename);
  104.  
  105.       if (ps->filename[l - len - 1] == '/'
  106.           && !strcmp (ps->filename + l - len, name))
  107.         {
  108.           if (ps->readin)
  109.         error ("Internal: readin pst found when no symtab found.");
  110.           return PSYMTAB_TO_SYMTAB (ps);
  111.         }
  112.     }
  113.     }
  114.   return 0;
  115. }
  116.  
  117. /* Lookup the symbol table of a source file named NAME.  Try a couple
  118.    of variations if the first lookup doesn't work.  */
  119.  
  120. struct symtab *
  121. lookup_symtab (name)
  122.      char *name;
  123. {
  124.   register struct symtab *s;
  125.   register char *copy;
  126.  
  127.   s = lookup_symtab_1 (name);
  128.   if (s) return s;
  129.  
  130.   /* If name not found as specified, see if adding ".c" helps.  */
  131.  
  132.   copy = (char *) alloca (strlen (name) + 3);
  133.   strcpy (copy, name);
  134.   strcat (copy, ".c");
  135.   s = lookup_symtab_1 (copy);
  136.   if (s) return s;
  137.  
  138.   /* We didn't find anything; die.  */
  139.   return 0;
  140. }
  141.  
  142. /* Lookup the partial symbol table of a source file named NAME.  This
  143.    only returns true on an exact match (ie. this semantics are
  144.    different from lookup_symtab.  */
  145.  
  146. struct partial_symtab *
  147. lookup_partial_symtab (name)
  148. char *name;
  149. {
  150.   register struct partial_symtab *s;
  151.   
  152.   for (s = partial_symtab_list; s; s = s->next)
  153.     if (!strcmp (name, s->filename))
  154.       return s;
  155.   
  156.   return 0;
  157. }
  158.  
  159. /* Return a typename for a struct/union/enum type
  160.    without the tag qualifier.  If the type has a NULL name,
  161.    NULL is returned.  */
  162. char *
  163. type_name_no_tag (type)
  164.      register struct type *type;
  165. {
  166.   register char *name = TYPE_NAME (type);
  167.   char *strchr ();
  168.   if (name == 0)
  169.     return 0;
  170.  
  171. #if 0
  172.   switch (TYPE_CODE (type))
  173.     {
  174.     case TYPE_CODE_STRUCT:
  175.       return name + 7;
  176.     case TYPE_CODE_UNION:
  177.       return name + 6;
  178.     case TYPE_CODE_ENUM:
  179.       return name + 5;
  180.     }
  181. #endif
  182.  
  183.   name = strchr (name, ' ');
  184.   if (name)
  185.     return name + 1;
  186.  
  187.   return TYPE_NAME (type);
  188. }
  189.  
  190. /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
  191.  
  192.    If this is a stubbed struct (i.e. declared as struct foo *), see if
  193.    we can find a full definition in some other file. If so, copy this
  194.    definition, so we can use it in future.  If not, set a flag so we 
  195.    don't waste too much time in future.  (FIXME, this doesn't seem
  196.    to be happening...)
  197.  
  198.    This used to be coded as a macro, but I don't think it is called 
  199.    often enough to merit such treatment.
  200. */
  201.  
  202. struct complaint stub_noname_complaint =
  203.   {"stub type has NULL name", 0, 0};
  204.  
  205. void 
  206. check_stub_type(type)
  207.      struct type *type;
  208. {
  209.   if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
  210.     {
  211.       char* name= type_name_no_tag (type);
  212.       struct symbol *sym;
  213.       if (name == 0)
  214.     {
  215.       complain (&stub_noname_complaint, 0);
  216.       return;
  217.     }
  218.       sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, 
  219.                (struct symtab **)NULL);
  220.       if (sym)
  221.     bcopy (SYMBOL_TYPE(sym), type, sizeof (struct type));
  222.     }
  223. }
  224.  
  225. /* Demangle a GDB method stub type.  */
  226. char *
  227. gdb_mangle_typename (type)
  228.      struct type *type;
  229. {
  230.   static struct type *last_type;
  231.   static char *mangled_typename;
  232.  
  233.   if (type != last_type)
  234.     {
  235.       /* Need a new type prefix.  */
  236.       char *strchr ();
  237.       char *newname = type_name_no_tag (type);
  238.       char buf[20];
  239.       int len;
  240.  
  241.       if (mangled_typename)
  242.     free (mangled_typename);
  243.  
  244.       len = strlen (newname);
  245.       sprintf (buf, "__%d", len);
  246.       mangled_typename = (char *)xmalloc (strlen (buf) + len + 1);
  247.       strcpy (mangled_typename, buf);
  248.       strcat (mangled_typename, newname);
  249.       /* Now we have built "__#newname".  */
  250.     }
  251.   return mangled_typename;
  252. }
  253.  
  254. /* Lookup a primitive type named NAME. 
  255.    Return zero if NAME is not a primitive type.*/
  256.  
  257. struct type *
  258. lookup_primitive_typename (name)
  259.      char *name;
  260. {
  261.    struct type ** const *p;
  262.  
  263.    for (p = current_language->la_builtin_type_vector; *p; p++)
  264.       if(!strcmp((**p)->name, name))
  265.      return **p;
  266.    return 0; 
  267. }
  268.  
  269. /* Lookup a typedef or primitive type named NAME,
  270.    visible in lexical block BLOCK.
  271.    If NOERR is nonzero, return zero if NAME is not suitably defined.  */
  272.  
  273. struct type *
  274. lookup_typename (name, block, noerr)
  275.      char *name;
  276.      struct block *block;
  277.      int noerr;
  278. {
  279.   register struct symbol *sym =
  280.     lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
  281.   if (sym == 0 || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
  282.     {
  283.       struct type *tmp;
  284.       tmp = lookup_primitive_typename (name);
  285.       if(tmp)
  286.      return tmp;
  287.       else if (!tmp && noerr)
  288.     return 0;
  289.       else
  290.      error ("No type named %s.", name);
  291.     }
  292.   return SYMBOL_TYPE (sym);
  293. }
  294.  
  295. struct type *
  296. lookup_unsigned_typename (name)
  297.      char *name;
  298. {
  299.   char *uns = alloca (strlen(name) + 10);
  300.  
  301.   strcpy (uns, "unsigned ");
  302.   strcpy (uns+9, name);
  303.   return lookup_typename (uns, (struct block *)0, 0);
  304. }
  305.  
  306. /* Lookup a structure type named "struct NAME",
  307.    visible in lexical block BLOCK.  */
  308.  
  309. struct type *
  310. lookup_struct (name, block)
  311.      char *name;
  312.      struct block *block;
  313. {
  314.   register struct symbol *sym 
  315.     = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
  316.  
  317.   if (sym == 0)
  318.     error ("No struct type named %s.", name);
  319.   if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
  320.     error ("This context has class, union or enum %s, not a struct.", name);
  321.   return SYMBOL_TYPE (sym);
  322. }
  323.  
  324. /* Lookup a union type named "union NAME",
  325.    visible in lexical block BLOCK.  */
  326.  
  327. struct type *
  328. lookup_union (name, block)
  329.      char *name;
  330.      struct block *block;
  331. {
  332.   register struct symbol *sym 
  333.     = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
  334.  
  335.   if (sym == 0)
  336.     error ("No union type named %s.", name);
  337.   if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
  338.     error ("This context has class, struct or enum %s, not a union.", name);
  339.   return SYMBOL_TYPE (sym);
  340. }
  341.  
  342. /* Lookup an enum type named "enum NAME",
  343.    visible in lexical block BLOCK.  */
  344.  
  345. struct type *
  346. lookup_enum (name, block)
  347.      char *name;
  348.      struct block *block;
  349. {
  350.   register struct symbol *sym 
  351.     = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
  352.   if (sym == 0)
  353.     error ("No enum type named %s.", name);
  354.   if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
  355.     error ("This context has class, struct or union %s, not an enum.", name);
  356.   return SYMBOL_TYPE (sym);
  357. }
  358.  
  359. /* Given a type TYPE, lookup the type of the component of type named
  360.    NAME.  
  361.    If NOERR is nonzero, return zero if NAME is not suitably defined.  */
  362.  
  363. struct type *
  364. lookup_struct_elt_type (type, name, noerr)
  365.      struct type *type;
  366.      char *name;
  367.      int noerr;
  368. {
  369.   int i;
  370.  
  371.   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  372.       && TYPE_CODE (type) != TYPE_CODE_UNION)
  373.     {
  374.       target_terminal_ours ();
  375.       fflush (stdout);
  376.       fprintf (stderr, "Type ");
  377.       type_print (type, "", stderr, -1);
  378.       error (" is not a structure or union type.");
  379.     }
  380.  
  381.   check_stub_type (type);
  382.  
  383.   for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
  384.     {
  385.       char *t_field_name = TYPE_FIELD_NAME (type, i);
  386.  
  387.       if (t_field_name && !strcmp (t_field_name, name))
  388.     return TYPE_FIELD_TYPE (type, i);
  389.     }
  390.   /* OK, it's not in this class.  Recursively check the baseclasses.  */
  391.   for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
  392.     {
  393.       struct type *t = lookup_struct_elt_type (TYPE_BASECLASS (type, i),
  394.                            name, 0);
  395.       if (t != NULL)
  396.     return t;
  397.     }
  398.  
  399.   if (noerr)
  400.     return NULL;
  401.   
  402.   target_terminal_ours ();
  403.   fflush (stdout);
  404.   fprintf (stderr, "Type ");
  405.   type_print (type, "", stderr, -1);
  406.   fprintf (stderr, " has no component named ");
  407.   fputs_filtered (name, stderr);
  408.   error (".");
  409.   return (struct type *)-1;    /* For lint */
  410. }
  411.  
  412. /* Given a type TYPE, return a type of pointers to that type.
  413.    May need to construct such a type if this is the first use.
  414.  
  415.    C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
  416.    to member types under control.  */
  417.  
  418. struct type *
  419. lookup_pointer_type (type)
  420.      struct type *type;
  421. {
  422.   register struct type *ptype = TYPE_POINTER_TYPE (type);
  423.   if (ptype) return TYPE_MAIN_VARIANT (ptype);
  424.  
  425.   /* This is the first time anyone wanted a pointer to a TYPE.  */
  426.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  427.     ptype  = (struct type *) xmalloc (sizeof (struct type));
  428.   else
  429.     ptype  = (struct type *) obstack_alloc (symbol_obstack,
  430.                         sizeof (struct type));
  431.  
  432.   bzero (ptype, sizeof (struct type));
  433.   TYPE_MAIN_VARIANT (ptype) = ptype;
  434.   TYPE_TARGET_TYPE (ptype) = type;
  435.   TYPE_POINTER_TYPE (type) = ptype;
  436.   /* New type is permanent if type pointed to is permanent.  */
  437.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  438.     TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
  439.   /* We assume the machine has only one representation for pointers!  */
  440.   /* FIXME:  This confuses host<->target data representations, and is a
  441.      poor assumption besides. */
  442.   TYPE_LENGTH (ptype) = sizeof (char *);
  443.   TYPE_CODE (ptype) = TYPE_CODE_PTR;
  444.   return ptype;
  445. }
  446.  
  447. struct type *
  448. lookup_reference_type (type)
  449.      struct type *type;
  450. {
  451.   register struct type *rtype = TYPE_REFERENCE_TYPE (type);
  452.   if (rtype) return TYPE_MAIN_VARIANT (rtype);
  453.  
  454.   /* This is the first time anyone wanted a pointer to a TYPE.  */
  455.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  456.     rtype  = (struct type *) xmalloc (sizeof (struct type));
  457.   else
  458.     rtype  = (struct type *) obstack_alloc (symbol_obstack,
  459.                         sizeof (struct type));
  460.  
  461.   bzero (rtype, sizeof (struct type));
  462.   TYPE_MAIN_VARIANT (rtype) = rtype;
  463.   TYPE_TARGET_TYPE (rtype) = type;
  464.   TYPE_REFERENCE_TYPE (type) = rtype;
  465.   /* New type is permanent if type pointed to is permanent.  */
  466.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  467.     TYPE_FLAGS (rtype) |= TYPE_FLAG_PERM;
  468.   /* We assume the machine has only one representation for pointers!  */
  469.   TYPE_LENGTH (rtype) = sizeof (char *);
  470.   TYPE_CODE (rtype) = TYPE_CODE_REF;
  471.   return rtype;
  472. }
  473.  
  474.  
  475. /* Implement direct support for MEMBER_TYPE in GNU C++.
  476.    May need to construct such a type if this is the first use.
  477.    The TYPE is the type of the member.  The DOMAIN is the type
  478.    of the aggregate that the member belongs to.  */
  479.  
  480. struct type *
  481. lookup_member_type (type, domain)
  482.      struct type *type, *domain;
  483. {
  484.   register struct type *mtype = TYPE_MAIN_VARIANT (type);
  485.   struct type *main_type;
  486.  
  487.   main_type = mtype;
  488.   while (mtype)
  489.     {
  490.       if (TYPE_DOMAIN_TYPE (mtype) == domain)
  491.     return mtype;
  492.       mtype = TYPE_NEXT_VARIANT (mtype);
  493.     }
  494.  
  495.   /* This is the first time anyone wanted this member type.  */
  496.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  497.     mtype  = (struct type *) xmalloc (sizeof (struct type));
  498.   else
  499.     mtype  = (struct type *) obstack_alloc (symbol_obstack,
  500.                         sizeof (struct type));
  501.  
  502.   bzero (mtype, sizeof (struct type));
  503.   if (main_type == 0)
  504.     main_type = mtype;
  505.   else
  506.     {
  507.       TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type);
  508.       TYPE_NEXT_VARIANT (main_type) = mtype;
  509.     }
  510.   TYPE_MAIN_VARIANT (mtype) = main_type;
  511.   TYPE_TARGET_TYPE (mtype) = type;
  512.   TYPE_DOMAIN_TYPE (mtype) = domain;
  513.   /* New type is permanent if type pointed to is permanent.  */
  514.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  515.     TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM;
  516.  
  517.   /* In practice, this is never used.  */
  518.   TYPE_LENGTH (mtype) = 1;
  519.   TYPE_CODE (mtype) = TYPE_CODE_MEMBER;
  520.  
  521. #if 0
  522.   /* Now splice in the new member pointer type.  */
  523.   if (main_type)
  524.     {
  525.       /* This type was not "smashed".  */
  526.       TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type);
  527.       TYPE_CHAIN (main_type) = mtype;
  528.     }
  529. #endif
  530.  
  531.   return mtype;
  532. }
  533.  
  534. /* Allocate a stub method whose return type is
  535.    TYPE.  We will fill in arguments later.  This always
  536.    returns a fresh type.  If we unify this type with
  537.    an existing type later, the storage allocated
  538.    here can be freed.  */
  539. struct type *
  540. allocate_stub_method (type)
  541.      struct type *type;
  542. {
  543.   struct type *mtype = (struct type *)xmalloc (sizeof (struct type));
  544.   bzero (mtype, sizeof (struct type));
  545.   TYPE_MAIN_VARIANT (mtype) = mtype;
  546.   TYPE_TARGET_TYPE (mtype) = type;
  547.   TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
  548.   TYPE_CODE (mtype) = TYPE_CODE_METHOD;
  549.   TYPE_LENGTH (mtype) = 1;
  550.   return mtype;
  551. }
  552.  
  553. /* Lookup a method type belonging to class DOMAIN, returning type TYPE,
  554.    and taking a list of arguments ARGS.
  555.    If one is not found, allocate a new one.  */
  556.  
  557. struct type *
  558. lookup_method_type (domain, type, args)
  559.      struct type *domain, *type, **args;
  560. {
  561.   register struct type *mtype = TYPE_MAIN_VARIANT (type);
  562.   struct type *main_type;
  563.  
  564.   main_type = mtype;
  565.   while (mtype)
  566.     {
  567.       if (TYPE_DOMAIN_TYPE (mtype) == domain)
  568.     {
  569.       struct type **t1 = args;
  570.       struct type **t2 = TYPE_ARG_TYPES (mtype);
  571.       if (t2)
  572.         {
  573.           int i;
  574.           for (i = 0; t1[i] != 0 && t1[i]->code != TYPE_CODE_VOID; i++)
  575.         if (t1[i] != t2[i])
  576.           break;
  577.           if (t1[i] == t2[i])
  578.         return mtype;
  579.         }
  580.     }
  581.       mtype = TYPE_NEXT_VARIANT (mtype);
  582.     }
  583.  
  584.   /* This is the first time anyone wanted this member type.  */
  585.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  586.     mtype  = (struct type *) xmalloc (sizeof (struct type));
  587.   else
  588.     mtype  = (struct type *) obstack_alloc (symbol_obstack,
  589.                         sizeof (struct type));
  590.  
  591.   bzero (mtype, sizeof (struct type));
  592.   if (main_type == 0)
  593.     main_type = mtype;
  594.   else
  595.     {
  596.       TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type);
  597.       TYPE_NEXT_VARIANT (main_type) = mtype;
  598.     }
  599.   TYPE_MAIN_VARIANT (mtype) = main_type;
  600.   TYPE_TARGET_TYPE (mtype) = type;
  601.   TYPE_DOMAIN_TYPE (mtype) = domain;
  602.   TYPE_ARG_TYPES (mtype) = args;
  603.   /* New type is permanent if type pointed to is permanent.  */
  604.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  605.     TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM;
  606.  
  607.   /* In practice, this is never used.  */
  608.   TYPE_LENGTH (mtype) = 1;
  609.   TYPE_CODE (mtype) = TYPE_CODE_METHOD;
  610.  
  611. #if 0
  612.   /* Now splice in the new member pointer type.  */
  613.   if (main_type)
  614.     {
  615.       /* This type was not "smashed".  */
  616.       TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type);
  617.       TYPE_CHAIN (main_type) = mtype;
  618.     }
  619. #endif
  620.  
  621.   return mtype;
  622. }
  623.  
  624. #if 0
  625. /* Given a type TYPE, return a type which has offset OFFSET,
  626.    via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
  627.    May need to construct such a type if none exists.  */
  628. struct type *
  629. lookup_basetype_type (type, offset, via_virtual, via_public)
  630.      struct type *type;
  631.      int offset;
  632.      int via_virtual, via_public;
  633. {
  634.   register struct type *btype = TYPE_MAIN_VARIANT (type);
  635.   struct type *main_type;
  636.  
  637.   if (offset != 0)
  638.     {
  639.       printf ("Internal error: type offset non-zero in lookup_basetype_type");
  640.       offset = 0;
  641.     }
  642.  
  643.   main_type = btype;
  644.   while (btype)
  645.     {
  646.       if (/* TYPE_OFFSET (btype) == offset
  647.       && */ TYPE_VIA_PUBLIC (btype) == via_public
  648.       && TYPE_VIA_VIRTUAL (btype) == via_virtual)
  649.     return btype;
  650.       btype = TYPE_NEXT_VARIANT (btype);
  651.     }
  652.  
  653.   /* This is the first time anyone wanted this member type.  */
  654.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  655.     btype  = (struct type *) xmalloc (sizeof (struct type));
  656.   else
  657.     btype  = (struct type *) obstack_alloc (symbol_obstack,
  658.                         sizeof (struct type));
  659.  
  660.   if (main_type == 0)
  661.     {
  662.       main_type = btype;
  663.       bzero (btype, sizeof (struct type));
  664.       TYPE_MAIN_VARIANT (btype) = main_type;
  665.     }
  666.   else
  667.     {
  668.       bcopy (main_type, btype, sizeof (struct type));
  669.       TYPE_NEXT_VARIANT (main_type) = btype;
  670.     }
  671. /* TYPE_OFFSET (btype) = offset; */
  672.   if (via_public)
  673.     TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_PUBLIC;
  674.   if (via_virtual)
  675.     TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_VIRTUAL;
  676.   /* New type is permanent if type pointed to is permanent.  */
  677.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  678.     TYPE_FLAGS (btype) |= TYPE_FLAG_PERM;
  679.  
  680.   /* In practice, this is never used.  */
  681.   TYPE_LENGTH (btype) = 1;
  682.   TYPE_CODE (btype) = TYPE_CODE_STRUCT;
  683.  
  684.   return btype;
  685. }
  686. #endif
  687.  
  688. /* Given a type TYPE, return a type of functions that return that type.
  689.    May need to construct such a type if this is the first use.  */
  690.  
  691. struct type *
  692. lookup_function_type (type)
  693.      struct type *type;
  694. {
  695.   register struct type *ptype = TYPE_FUNCTION_TYPE (type);
  696.   if (ptype) return ptype;
  697.  
  698.   /* This is the first time anyone wanted a function returning a TYPE.  */
  699.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  700.     ptype  = (struct type *) xmalloc (sizeof (struct type));
  701.   else
  702.     ptype  = (struct type *) obstack_alloc (symbol_obstack,
  703.                         sizeof (struct type));
  704.  
  705.   bzero (ptype, sizeof (struct type));
  706.   TYPE_TARGET_TYPE (ptype) = type;
  707.   TYPE_FUNCTION_TYPE (type) = ptype;
  708.   /* New type is permanent if type returned is permanent.  */
  709.   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
  710.     TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
  711.   TYPE_LENGTH (ptype) = 1;
  712.   TYPE_CODE (ptype) = TYPE_CODE_FUNC;
  713.   TYPE_NFIELDS (ptype) = 0;
  714.   return ptype;
  715. }
  716.  
  717. /* Create an array type.  Elements will be of type TYPE, and there will
  718.    be NUM of them.
  719.  
  720.    Eventually this should be extended to take two more arguments which
  721.    specify the bounds of the array and the type of the index.
  722.    It should also be changed to be a "lookup" function, with the
  723.    appropriate data structures added to the type field.
  724.    Then read array type should call here.  */
  725.  
  726. struct type *
  727. create_array_type (element_type, number)
  728.      struct type *element_type;
  729.      int number;
  730. {
  731.   struct type *result_type = (struct type *)
  732.     obstack_alloc (symbol_obstack, sizeof (struct type));
  733.   struct type *range_type;
  734.  
  735.   bzero (result_type, sizeof (struct type));
  736.  
  737.   TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
  738.   TYPE_TARGET_TYPE (result_type) = element_type;
  739.   TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type);
  740.   TYPE_NFIELDS (result_type) = 1;
  741.   TYPE_FIELDS (result_type) =
  742.     (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field));
  743.  
  744.   {
  745.     /* Create range type.  */
  746.     range_type = (struct type *) obstack_alloc (symbol_obstack,
  747.                         sizeof (struct type));
  748.     TYPE_CODE (range_type) = TYPE_CODE_RANGE;
  749.     TYPE_TARGET_TYPE (range_type) = builtin_type_int;  /* FIXME */
  750.  
  751.     /* This should never be needed.  */
  752.     TYPE_LENGTH (range_type) = sizeof (int);
  753.  
  754.     TYPE_NFIELDS (range_type) = 2;
  755.     TYPE_FIELDS (range_type) =
  756.       (struct field *) obstack_alloc (symbol_obstack,
  757.                       2 * sizeof (struct field));
  758.     TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */
  759.     TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */
  760.     TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */
  761.     TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */
  762.   }
  763.   TYPE_FIELD_TYPE(result_type,0)=range_type;
  764.   TYPE_VPTR_FIELDNO (result_type) = -1;
  765.  
  766.   return result_type;
  767. }
  768.  
  769.  
  770. /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.  */
  771.  
  772. void
  773. smash_to_member_type (type, domain, to_type)
  774.      struct type *type, *domain, *to_type;
  775. {
  776.   bzero (type, sizeof (struct type));
  777.   TYPE_TARGET_TYPE (type) = to_type;
  778.   TYPE_DOMAIN_TYPE (type) = domain;
  779.  
  780.   /* In practice, this is never needed.  */
  781.   TYPE_LENGTH (type) = 1;
  782.   TYPE_CODE (type) = TYPE_CODE_MEMBER;
  783.  
  784.   TYPE_MAIN_VARIANT (type) = lookup_member_type (domain, to_type);
  785. }
  786.  
  787. /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.  */
  788.  
  789. void
  790. smash_to_method_type (type, domain, to_type, args)
  791.      struct type *type, *domain, *to_type, **args;
  792. {
  793.   bzero (type, sizeof (struct type));
  794.   TYPE_TARGET_TYPE (type) = to_type;
  795.   TYPE_DOMAIN_TYPE (type) = domain;
  796.   TYPE_ARG_TYPES (type) = args;
  797.  
  798.   /* In practice, this is never needed.  */
  799.   TYPE_LENGTH (type) = 1;
  800.   TYPE_CODE (type) = TYPE_CODE_METHOD;
  801.  
  802.   TYPE_MAIN_VARIANT (type) = lookup_method_type (domain, to_type, args);
  803. }
  804.  
  805. /* Find which partial symtab on the partial_symtab_list contains
  806.    PC.  Return 0 if none.  */
  807.  
  808. struct partial_symtab *
  809. find_pc_psymtab (pc)
  810.      register CORE_ADDR pc;
  811. {
  812.   register struct partial_symtab *ps;
  813.  
  814.   for (ps = partial_symtab_list; ps; ps = ps->next)
  815.     if (pc >= ps->textlow && pc < ps->texthigh)
  816.       return ps;
  817.  
  818.   return 0;
  819. }
  820.  
  821. /* Find which partial symbol within a psymtab contains PC.  Return 0
  822.    if none.  Check all psymtabs if PSYMTAB is 0.  */
  823. struct partial_symbol *
  824. find_pc_psymbol (psymtab, pc)
  825.      struct partial_symtab *psymtab;
  826.      CORE_ADDR pc;
  827. {
  828.   struct partial_symbol *best, *p;
  829.   CORE_ADDR best_pc;
  830.   
  831.   if (!psymtab)
  832.     psymtab = find_pc_psymtab (pc);
  833.   if (!psymtab)
  834.     return 0;
  835.  
  836.   best_pc = psymtab->textlow - 1;
  837.  
  838.   for (p = static_psymbols.list + psymtab->statics_offset;
  839.        (p - (static_psymbols.list + psymtab->statics_offset)
  840.     < psymtab->n_static_syms);
  841.        p++)
  842.     if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
  843.     && SYMBOL_CLASS (p) == LOC_BLOCK
  844.     && pc >= SYMBOL_VALUE_ADDRESS (p)
  845.     && SYMBOL_VALUE_ADDRESS (p) > best_pc)
  846.       {
  847.     best_pc = SYMBOL_VALUE_ADDRESS (p);
  848.     best = p;
  849.       }
  850.   if (best_pc == psymtab->textlow - 1)
  851.     return 0;
  852.   return best;
  853. }
  854.  
  855.  
  856. /* Find the definition for a specified symbol name NAME
  857.    in namespace NAMESPACE, visible from lexical block BLOCK.
  858.    Returns the struct symbol pointer, or zero if no symbol is found.
  859.    If SYMTAB is non-NULL, store the symbol table in which the
  860.    symbol was found there, or NULL if not found.
  861.    C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
  862.    NAME is a field of the current implied argument `this'.  If so set
  863.    *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. 
  864.    BLOCK_FOUND is set to the block in which NAME is found (in the case of
  865.    a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
  866.  
  867. struct symbol *
  868. lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
  869.      char *name;
  870.      register struct block *block;
  871.      enum namespace namespace;
  872.      int *is_a_field_of_this;
  873.      struct symtab **symtab;
  874. {
  875.   register struct symbol *sym;
  876.   register struct symtab *s;
  877.   register struct partial_symtab *ps;
  878.   struct blockvector *bv;
  879.  
  880.   /* Search specified block and its superiors.  */
  881.   while (block != 0)
  882.     {
  883.       sym = lookup_block_symbol (block, name, namespace);
  884.       if (sym) 
  885.     {
  886.       block_found = block;
  887.       if (symtab != NULL)
  888.         {
  889.           /* Search the list of symtabs for one which contains the
  890.          address of the start of this block.  */
  891.           struct block *b;
  892.           for (s = symtab_list; s; s = s->next)
  893.         {
  894.           bv = BLOCKVECTOR (s);
  895.           b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  896.           if (BLOCK_START (b) <= BLOCK_START (block)
  897.               && BLOCK_END (b) > BLOCK_START (block))
  898.             break;
  899.         }
  900.           *symtab = s;
  901.         }
  902.  
  903.       return sym;
  904.     }
  905.       block = BLOCK_SUPERBLOCK (block);
  906.     }
  907.  
  908.   /* But that doesn't do any demangling for the STATIC_BLOCK.
  909.      I'm not sure whether demangling is needed in the case of
  910.      nested function in inner blocks; if so this needs to be changed.
  911.      
  912.      Don't need to mess with the psymtabs; if we have a block,
  913.      that file is read in.  If we don't, then we deal later with
  914.      all the psymtab stuff that needs checking.  */
  915.   if (namespace == VAR_NAMESPACE && block != NULL)
  916.     {
  917.       struct block *b;
  918.       /* Find the right symtab.  */
  919.       for (s = symtab_list; s; s = s->next)
  920.     {
  921.       bv = BLOCKVECTOR (s);
  922.       b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
  923.       if (BLOCK_START (b) <= BLOCK_START (block)
  924.           && BLOCK_END (b) > BLOCK_START (block))
  925.         {
  926.           sym = lookup_demangled_block_symbol (b, name);
  927.           if (sym)
  928.         {
  929.           block_found = b;
  930.           if (symtab != NULL)
  931.             *symtab = s;
  932.           return sym;
  933.         }
  934.         }
  935.     }
  936.     }
  937.  
  938.  
  939.   /* C++: If requested to do so by the caller, 
  940.      check to see if NAME is a field of `this'. */
  941.   if (is_a_field_of_this)
  942.     {
  943.       struct value *v = value_of_this (0);
  944.       
  945.       *is_a_field_of_this = 0;
  946.       if (v && check_field (v, name))
  947.     {
  948.       *is_a_field_of_this = 1;
  949.       if (symtab != NULL)
  950.         *symtab = NULL;
  951.       return 0;
  952.     }
  953.     }
  954.  
  955.   /* Now search all global blocks.  Do the symtab's first, then
  956.      check the psymtab's */
  957.  
  958.   for (s = symtab_list; s; s = s->next)
  959.     {
  960.       bv = BLOCKVECTOR (s);
  961.       block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  962.       sym = lookup_block_symbol (block, name, namespace);
  963.       if (sym) 
  964.     {
  965.       block_found = block;
  966.       if (symtab != NULL)
  967.         *symtab = s;
  968.       return sym;
  969.     }
  970.     }
  971.  
  972.   /* Check for the possibility of the symbol being a global function
  973.      that is stored on the misc function vector.  Eventually, all
  974.      global symbols might be resolved in this way.  */
  975.   
  976.   if (namespace == VAR_NAMESPACE)
  977.     {
  978.       int ind = lookup_misc_func (name);
  979.  
  980.       /* Look for a mangled C++ name for NAME. */
  981.       if (ind == -1)
  982.     {
  983.       int name_len = strlen (name);
  984.  
  985.       for (ind = misc_function_count; --ind >= 0; ) {
  986.         /* Assume orginal name is prefix of mangled name. */
  987.         if (!strncmp (misc_function_vector[ind].name, name, name_len))
  988.           {
  989.         char *demangled =
  990.           cplus_demangle(misc_function_vector[ind].name, -1);
  991.         if (demangled != NULL)
  992.           {
  993.             int cond = strcmp (demangled, name);
  994.             free (demangled);
  995.             if (!cond)
  996.               break;
  997.           }
  998.           }
  999.       }
  1000.       /* Loop terminates on no match with ind == -1. */
  1001.         }
  1002.  
  1003.       if (ind != -1)
  1004.     {
  1005.       s = find_pc_symtab (misc_function_vector[ind].address);
  1006.       /* If S is zero, there are no debug symbols for this file.
  1007.          Skip this stuff and check for matching static symbols below. */
  1008.       if (s)
  1009.         {
  1010.           bv = BLOCKVECTOR (s);
  1011.           block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  1012.           sym = lookup_block_symbol (block, misc_function_vector[ind].name,
  1013.                          namespace);
  1014.           /* sym == 0 if symbol was found in the misc_function_vector
  1015.          but not in the symtab.
  1016.          Return 0 to use the misc_function definition of "foo_".
  1017.  
  1018.          This happens for Fortran  "foo_" symbols,
  1019.          which are "foo" in the symtab.
  1020.  
  1021.          This can also happen if "asm" is used to make a
  1022.          regular symbol but not a debugging symbol, e.g.
  1023.          asm(".globl _main");
  1024.          asm("_main:");
  1025.          */
  1026.  
  1027.           if (symtab != NULL)
  1028.         *symtab = s;
  1029.           return sym;
  1030.         }
  1031.     }
  1032.     }
  1033.       
  1034.   for (ps = partial_symtab_list; ps; ps = ps->next) {
  1035.     if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
  1036.       {
  1037.     s = PSYMTAB_TO_SYMTAB(ps);
  1038.     bv = BLOCKVECTOR (s);
  1039.     block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  1040.     sym = lookup_block_symbol (block, name, namespace);
  1041.     if (!sym)
  1042.       error ("Internal: global symbol found in psymtab but not in symtab");
  1043.     if (symtab != NULL)
  1044.       *symtab = s;
  1045.     return sym;
  1046.       }
  1047.   }
  1048.  
  1049.   /* Now search all per-file blocks.
  1050.      Not strictly correct, but more useful than an error.
  1051.      Do the symtabs first, then check the psymtabs */
  1052.  
  1053.   for (s = symtab_list; s; s = s->next)
  1054.     {
  1055.       bv = BLOCKVECTOR (s);
  1056.       block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
  1057.       sym = lookup_block_symbol (block, name, namespace);
  1058.       if (sym) 
  1059.     {
  1060.       block_found = block;
  1061.       if (symtab != NULL)
  1062.         *symtab = s;
  1063.       return sym;
  1064.     }
  1065.     }
  1066.  
  1067.   for (ps = partial_symtab_list; ps; ps = ps->next)
  1068.     if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
  1069.       {
  1070.     s = PSYMTAB_TO_SYMTAB(ps);
  1071.     bv = BLOCKVECTOR (s);
  1072.     block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
  1073.     sym = lookup_block_symbol (block, name, namespace);
  1074.     if (!sym)
  1075.       error ("Internal: static symbol found in psymtab but not in symtab");
  1076.     if (symtab != NULL)
  1077.       *symtab = s;
  1078.     return sym;
  1079.       }
  1080.  
  1081.   /* Now search all per-file blocks for static mangled symbols.
  1082.      Do the symtabs first, then check the psymtabs.  */
  1083.  
  1084.   if (namespace ==  VAR_NAMESPACE)
  1085.     {
  1086.       for (s = symtab_list; s; s = s->next)
  1087.     {
  1088.       bv = BLOCKVECTOR (s);
  1089.       block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
  1090.       sym = lookup_demangled_block_symbol (block, name);
  1091.       if (sym) 
  1092.         {
  1093.           block_found = block;
  1094.           if (symtab != NULL)
  1095.         *symtab = s;
  1096.           return sym;
  1097.         }
  1098.     }
  1099.  
  1100.       for (ps = partial_symtab_list; ps; ps = ps->next)
  1101.     if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
  1102.       {
  1103.         s = PSYMTAB_TO_SYMTAB(ps);
  1104.         bv = BLOCKVECTOR (s);
  1105.         block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
  1106.         sym = lookup_demangled_block_symbol (block, name);
  1107.         if (!sym)
  1108.           error ("Internal: mangled static symbol found in psymtab but not in symtab");
  1109.         if (symtab != NULL)
  1110.           *symtab = s;
  1111.         return sym;
  1112.       }
  1113.     }
  1114.  
  1115.   if (symtab != NULL)
  1116.     *symtab = NULL;
  1117.   return 0;
  1118. }
  1119.  
  1120. /* Look for a static demangled symbol in block BLOCK.  */
  1121.  
  1122. static struct symbol *
  1123. lookup_demangled_block_symbol (block, name)
  1124.      register struct block *block;
  1125.      char *name;
  1126. {
  1127.   register int bot, top, inc;
  1128.   register struct symbol *sym;
  1129.  
  1130.   bot = 0;
  1131.   top = BLOCK_NSYMS (block);
  1132.   inc = name[0];
  1133.  
  1134.   while (bot < top)
  1135.     {
  1136.       sym = BLOCK_SYM (block, bot);
  1137.       if (SYMBOL_NAME (sym)[0] == inc
  1138.       && SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
  1139.     {
  1140.       char *demangled = cplus_demangle(SYMBOL_NAME (sym), -1);
  1141.       if (demangled != NULL)
  1142.         {
  1143.           int cond = strcmp (demangled, name);
  1144.           free (demangled);
  1145.           if (!cond) {
  1146.             return sym;
  1147.           } else {
  1148.         if ((lisp_strcmp(SYMBOL_NAME(sym),name) == 0)) {
  1149.           return(sym);
  1150.         }
  1151.           }
  1152.         }
  1153.     }
  1154.       bot++;
  1155.     }
  1156.  
  1157.   return 0;
  1158. }
  1159.  
  1160. /* Look, in partial_symtab PST, for static mangled symbol NAME. */
  1161.  
  1162. static struct partial_symbol *
  1163. lookup_demangled_partial_symbol (pst, name)
  1164.      struct partial_symtab *pst;
  1165.      char *name;
  1166. {
  1167.   struct partial_symbol *start, *psym;
  1168.   int length = pst->n_static_syms;
  1169.   register int inc = name[0];
  1170.  
  1171.   if (!length)
  1172.     return (struct partial_symbol *) 0;
  1173.   
  1174.   start = static_psymbols.list + pst->statics_offset;
  1175.   for (psym = start; psym < start + length; psym++)
  1176.     {
  1177.       if (SYMBOL_NAME (psym)[0] == inc
  1178.       && SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
  1179.     {
  1180.       char *demangled = cplus_demangle(SYMBOL_NAME (psym), -1);
  1181.       if (demangled != NULL)
  1182.         {
  1183.           int cond = strcmp (demangled, name);
  1184.           free (demangled);
  1185.           if (!cond) {
  1186.             return psym;
  1187.           } else {
  1188.         if ((lisp_strcmp(SYMBOL_NAME(psym),name) == 0)) {
  1189.           return(psym);
  1190.         }
  1191.           }
  1192.         }
  1193.     }
  1194.     }
  1195.  
  1196.   return (struct partial_symbol *) 0;
  1197. }
  1198.  
  1199. /* Look, in partial_symtab PST, for symbol NAME.  Check the global
  1200.    symbols if GLOBAL, the static symbols if not */
  1201.  
  1202. static struct partial_symbol *
  1203. lookup_partial_symbol (pst, name, global, namespace)
  1204.      struct partial_symtab *pst;
  1205.      char *name;
  1206.      int global;
  1207.      enum namespace namespace;
  1208. {
  1209.   struct partial_symbol *start, *psym;
  1210.   int length = (global ? pst->n_global_syms : pst->n_static_syms);
  1211.  
  1212.   if (!length)
  1213.     return (struct partial_symbol *) 0;
  1214.   
  1215.   start = (global ?
  1216.        global_psymbols.list + pst->globals_offset :
  1217.        static_psymbols.list + pst->statics_offset  );
  1218.  
  1219.   if (global)            /* This means we can use a binary */
  1220.                 /* search.  */
  1221.     {
  1222.       struct partial_symbol *top, *bottom, *center;
  1223.  
  1224.       /* Binary search.  This search is guaranteed to end with center
  1225.          pointing at the earliest partial symbol with the correct
  1226.      name.  At that point *all* partial symbols with that name
  1227.      will be checked against the correct namespace. */
  1228.       bottom = start;
  1229.       top = start + length - 1;
  1230.       while (top > bottom)
  1231.     {
  1232.       center = bottom + (top - bottom) / 2;
  1233.  
  1234.       assert (center < top);
  1235.       
  1236.       if (strcmp (SYMBOL_NAME (center), name) >= 0)
  1237.         top = center;
  1238.       else
  1239.         bottom = center + 1;
  1240.     }
  1241.       assert (top == bottom);
  1242.       
  1243.       while (!strcmp (SYMBOL_NAME (top), name))
  1244.     {
  1245.       if (SYMBOL_NAMESPACE (top) == namespace)
  1246.         return top;
  1247.       top ++;
  1248.     }
  1249.     }
  1250.   else
  1251.     {
  1252.       /* Can't use a binary search */
  1253.       for (psym = start; psym < start + length; psym++)
  1254.     if (namespace == SYMBOL_NAMESPACE (psym)
  1255.         && !lisp_strcmp (name, SYMBOL_NAME (psym)))
  1256.       return psym;
  1257.     }
  1258.  
  1259.   return (struct partial_symbol *) 0;
  1260. }
  1261.  
  1262. /* Look for a symbol in block BLOCK.  */
  1263.  
  1264. struct symbol *
  1265. lookup_block_symbol (block, name, namespace)
  1266.      register struct block *block;
  1267.      char *name;
  1268.      enum namespace namespace;
  1269. {
  1270.   register int bot, top, inc;
  1271.   register struct symbol *sym, *parameter_sym;
  1272.  
  1273.   top = BLOCK_NSYMS (block);
  1274.   bot = 0;
  1275.  
  1276.   /* If the blocks's symbols were sorted, start with a binary search.  */
  1277.  
  1278.   if (BLOCK_SHOULD_SORT (block))
  1279.     {
  1280.       /* First, advance BOT to not far before
  1281.      the first symbol whose name is NAME.  */
  1282.  
  1283.       while (1)
  1284.     {
  1285.       inc = (top - bot + 1);
  1286.       /* No need to keep binary searching for the last few bits worth.  */
  1287.       if (inc < 4)
  1288.         break;
  1289.       inc = (inc >> 1) + bot;
  1290.       sym = BLOCK_SYM (block, inc);
  1291.       if (SYMBOL_NAME (sym)[0] < name[0])
  1292.         bot = inc;
  1293.       else if (SYMBOL_NAME (sym)[0] > name[0])
  1294.         top = inc;
  1295.       else if (strcmp (SYMBOL_NAME (sym), name) < 0)
  1296.         bot = inc;
  1297.       else
  1298.         top = inc;
  1299.     }
  1300.  
  1301.       /* Now scan forward until we run out of symbols,
  1302.      find one whose name is greater than NAME,
  1303.      or find one we want.
  1304.      If there is more than one symbol with the right name and namespace,
  1305.      we return the first one.  dbxread.c is careful to make sure
  1306.      that if one is a register then it comes first.  */
  1307.  
  1308.       top = BLOCK_NSYMS (block);
  1309.       while (bot < top)
  1310.     {
  1311.       sym = BLOCK_SYM (block, bot);
  1312.       inc = SYMBOL_NAME (sym)[0] - name[0];
  1313.       if (inc == 0)
  1314.         inc = lisp_strcmp (SYMBOL_NAME (sym), name);
  1315.       if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
  1316.         return sym;
  1317.       if (inc > 0)
  1318.         return 0;
  1319.       bot++;
  1320.     }
  1321.       return 0;
  1322.     }
  1323.  
  1324.   /* Here if block isn't sorted.
  1325.      This loop is equivalent to the loop above,
  1326.      but hacked greatly for speed.
  1327.  
  1328.      Note that parameter symbols do not always show up last in the
  1329.      list; this loop makes sure to take anything else other than
  1330.      parameter symbols first; it only uses parameter symbols as a
  1331.      last resort.  Note that this only takes up extra computation
  1332.      time on a match.  */
  1333.  
  1334.   parameter_sym = (struct symbol *) 0;
  1335.   top = BLOCK_NSYMS (block);
  1336.   inc = name[0];
  1337.   while (bot < top)
  1338.     {
  1339.       sym = BLOCK_SYM (block, bot);
  1340.       if (!lisp_strcmp (SYMBOL_NAME (sym), name)
  1341.       && SYMBOL_NAMESPACE (sym) == namespace)
  1342.     {
  1343.       if (SYMBOL_CLASS (sym) == LOC_ARG
  1344.           || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
  1345.           || SYMBOL_CLASS (sym) == LOC_REF_ARG
  1346.           || SYMBOL_CLASS (sym) == LOC_REGPARM)
  1347.         parameter_sym = sym;
  1348.       else
  1349.         return sym;
  1350.     }
  1351.       bot++;
  1352.     }
  1353.   return parameter_sym;        /* Will be 0 if not found. */
  1354. }
  1355.  
  1356. /* Return the symbol for the function which contains a specified
  1357.    lexical block, described by a struct block BL.  */
  1358.  
  1359. struct symbol *
  1360. block_function (bl)
  1361.      struct block *bl;
  1362. {
  1363.   while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
  1364.     bl = BLOCK_SUPERBLOCK (bl);
  1365.  
  1366.   return BLOCK_FUNCTION (bl);
  1367. }
  1368.  
  1369. /* Subroutine of find_pc_line */
  1370.  
  1371. struct symtab *
  1372. find_pc_symtab (pc)
  1373.      register CORE_ADDR pc;
  1374. {
  1375.   register struct block *b;
  1376.   struct blockvector *bv;
  1377.   register struct symtab *s;
  1378.   register struct partial_symtab *ps;
  1379.  
  1380.   /* Search all symtabs for one whose file contains our pc */
  1381.  
  1382.   for (s = symtab_list; s; s = s->next)
  1383.     {
  1384.       bv = BLOCKVECTOR (s);
  1385.       b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  1386.       if (BLOCK_START (b) <= pc
  1387.       && BLOCK_END (b) > pc)
  1388.     break;
  1389.     }
  1390.  
  1391.   if (!s)
  1392.     {
  1393.       ps = find_pc_psymtab (pc);
  1394.       if (ps && ps->readin)
  1395.     printf_filtered (
  1396.       "(Internal error: pc in read in psymtab, but not in symtab.)\n");
  1397.  
  1398.       if (ps)
  1399.     s = PSYMTAB_TO_SYMTAB (ps);
  1400.     }
  1401.  
  1402.   return s;
  1403. }
  1404.  
  1405. /* Find the source file and line number for a given PC value.
  1406.    Return a structure containing a symtab pointer, a line number,
  1407.    and a pc range for the entire source line.
  1408.    The value's .pc field is NOT the specified pc.
  1409.    NOTCURRENT nonzero means, if specified pc is on a line boundary,
  1410.    use the line that ends there.  Otherwise, in that case, the line
  1411.    that begins there is used.  */
  1412.  
  1413. struct symtab_and_line
  1414. find_pc_line (pc, notcurrent)
  1415.      CORE_ADDR pc;
  1416.      int notcurrent;
  1417. {
  1418.   struct symtab *s;
  1419.   register struct linetable *l;
  1420.   register int len;
  1421.   register int i;
  1422.   register struct linetable_entry *item;
  1423.   struct symtab_and_line val;
  1424.   struct blockvector *bv;
  1425.  
  1426.   /* Info on best line seen so far, and where it starts, and its file.  */
  1427.  
  1428.   int best_line = 0;
  1429.   CORE_ADDR best_pc = 0;
  1430.   CORE_ADDR best_end = 0;
  1431.   struct symtab *best_symtab = 0;
  1432.  
  1433.   /* Store here the first line number
  1434.      of a file which contains the line at the smallest pc after PC.
  1435.      If we don't find a line whose range contains PC,
  1436.      we will use a line one less than this,
  1437.      with a range from the start of that file to the first line's pc.  */
  1438.   int alt_line = 0;
  1439.   CORE_ADDR alt_pc = 0;
  1440.   struct symtab *alt_symtab = 0;
  1441.  
  1442.   /* Info on best line seen in this file.  */
  1443.  
  1444.   int prev_line;
  1445.   CORE_ADDR prev_pc;
  1446.  
  1447.   /* Info on first line of this file.  */
  1448.  
  1449.   int first_line;
  1450.   CORE_ADDR first_pc;
  1451.  
  1452.   /* If this pc is not from the current frame,
  1453.      it is the address of the end of a call instruction.
  1454.      Quite likely that is the start of the following statement.
  1455.      But what we want is the statement containing the instruction.
  1456.      Fudge the pc to make sure we get that.  */
  1457.  
  1458.   if (notcurrent) pc -= 1;
  1459.  
  1460.   s = find_pc_symtab (pc);
  1461.   if (s == 0)
  1462.     {
  1463.       val.symtab = 0;
  1464.       val.line = 0;
  1465.       val.pc = pc;
  1466.       val.end = 0;
  1467.       return val;
  1468.     }
  1469.  
  1470.   bv = BLOCKVECTOR (s);
  1471.  
  1472.   /* Look at all the symtabs that share this blockvector.
  1473.      They all have the same apriori range, that we found was right;
  1474.      but they have different line tables.  */
  1475.  
  1476.   for (; s && BLOCKVECTOR (s) == bv; s = s->next)
  1477.     {
  1478.       /* Find the best line in this symtab.  */
  1479.       l = LINETABLE (s);
  1480.       len = l->nitems;
  1481.       prev_line = -1;
  1482.       first_line = -1;
  1483.       for (i = 0; i < len; i++)
  1484.     {
  1485.       item = &(l->item[i]);
  1486.       
  1487.       if (first_line < 0)
  1488.         {
  1489.           first_line = item->line;
  1490.           first_pc = item->pc;
  1491.         }
  1492.       /* Return the last line that did not start after PC.  */
  1493.       if (pc >= item->pc)
  1494.         {
  1495.           prev_line = item->line;
  1496.           prev_pc = item->pc;
  1497.         }
  1498.       else
  1499.         break;
  1500.     }
  1501.  
  1502.       /* Is this file's best line closer than the best in the other files?
  1503.      If so, record this file, and its best line, as best so far.  */
  1504.       if (prev_line >= 0 && prev_pc > best_pc)
  1505.     {
  1506.       best_pc = prev_pc;
  1507.       best_line = prev_line;
  1508.       best_symtab = s;
  1509.       if (i < len)
  1510.         best_end = item->pc;
  1511.       else
  1512.         best_end = 0;
  1513.     }
  1514.       /* Is this file's first line closer than the first lines of other files?
  1515.      If so, record this file, and its first line, as best alternate.  */
  1516.       if (first_line >= 0 && first_pc > pc
  1517.       && (alt_pc == 0 || first_pc < alt_pc))
  1518.     {
  1519.       alt_pc = first_pc;
  1520.       alt_line = first_line;
  1521.       alt_symtab = s;
  1522.     }
  1523.     }
  1524.   if (best_symtab == 0)
  1525.     {
  1526.       val.symtab = alt_symtab;
  1527.       val.line = alt_line - 1;
  1528.       val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
  1529.       val.end = alt_pc;
  1530.     }
  1531.   else
  1532.     {
  1533.       val.symtab = best_symtab;
  1534.       val.line = best_line;
  1535.       val.pc = best_pc;
  1536.       val.end = (best_end ? best_end
  1537.            : (alt_pc ? alt_pc
  1538.               : BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))));
  1539.     }
  1540.   return val;
  1541. }
  1542.  
  1543. /* Find the PC value for a given source file and line number.
  1544.    Returns zero for invalid line number.
  1545.    The source file is specified with a struct symtab.  */
  1546.  
  1547. CORE_ADDR
  1548. find_line_pc (symtab, line)
  1549.      struct symtab *symtab;
  1550.      int line;
  1551. {
  1552.   register struct linetable *l;
  1553.   register int ind;
  1554.   int dummy;
  1555.  
  1556.   if (symtab == 0)
  1557.     return 0;
  1558.   l = LINETABLE (symtab);
  1559.   ind = find_line_common(l, line, &dummy);
  1560.   return (ind >= 0) ? l->item[ind].pc : 0;
  1561. }
  1562.  
  1563. /* Find the range of pc values in a line.
  1564.    Store the starting pc of the line into *STARTPTR
  1565.    and the ending pc (start of next line) into *ENDPTR.
  1566.    Returns 1 to indicate success.
  1567.    Returns 0 if could not find the specified line.  */
  1568.  
  1569. int
  1570. find_line_pc_range (symtab, thisline, startptr, endptr)
  1571.      struct symtab *symtab;
  1572.      int thisline;
  1573.      CORE_ADDR *startptr, *endptr;
  1574. {
  1575.   register struct linetable *l;
  1576.   register int ind;
  1577.   int exact_match;        /* did we get an exact linenumber match */
  1578.  
  1579.   if (symtab == 0)
  1580.     return 0;
  1581.  
  1582.   l = LINETABLE (symtab);
  1583.   ind = find_line_common (l, thisline, &exact_match);
  1584.   if (ind >= 0)
  1585.     {
  1586.       *startptr = l->item[ind].pc;
  1587.       /* If we have not seen an entry for the specified line,
  1588.      assume that means the specified line has zero bytes.  */
  1589.       if (!exact_match || ind == l->nitems-1)
  1590.     *endptr = *startptr;
  1591.       else
  1592.     /* Perhaps the following entry is for the following line.
  1593.        It's worth a try.  */
  1594.     if (ind+1 < l->nitems
  1595.      && l->item[ind+1].line == thisline + 1)
  1596.       *endptr = l->item[ind+1].pc;
  1597.     else
  1598.       *endptr = find_line_pc (symtab, thisline+1);
  1599.       return 1;
  1600.     }
  1601.  
  1602.   return 0;
  1603. }
  1604.  
  1605. /* Given a line table and a line number, return the index into the line
  1606.    table for the pc of the nearest line whose number is >= the specified one.
  1607.    Return -1 if none is found.  The value is >= 0 if it is an index.
  1608.  
  1609.    Set *EXACT_MATCH nonzero if the value returned is an exact match.  */
  1610.  
  1611. static int
  1612. find_line_common (l, lineno, exact_match)
  1613.      register struct linetable *l;
  1614.      register int lineno;
  1615.      int *exact_match;
  1616. {
  1617.   register int i;
  1618.   register int len;
  1619.  
  1620.   /* BEST is the smallest linenumber > LINENO so far seen,
  1621.      or 0 if none has been seen so far.
  1622.      BEST_INDEX identifies the item for it.  */
  1623.  
  1624.   int best_index = -1;
  1625.   int best = 0;
  1626.  
  1627.   if (lineno <= 0)
  1628.     return -1;
  1629.  
  1630.   len = l->nitems;
  1631.   for (i = 0; i < len; i++)
  1632.     {
  1633.       register struct linetable_entry *item = &(l->item[i]);
  1634.  
  1635.       if (item->line == lineno)
  1636.     {
  1637.       *exact_match = 1;
  1638.       return i;
  1639.     }
  1640.  
  1641.       if (item->line > lineno && (best == 0 || item->line < best))
  1642.     {
  1643.       best = item->line;
  1644.       best_index = i;
  1645.     }
  1646.     }
  1647.  
  1648.   /* If we got here, we didn't get an exact match.  */
  1649.  
  1650.   *exact_match = 0;
  1651.   return best_index;
  1652. }
  1653.  
  1654. int
  1655. find_pc_line_pc_range (pc, startptr, endptr)
  1656.      CORE_ADDR pc;
  1657.      CORE_ADDR *startptr, *endptr;
  1658. {
  1659.   struct symtab_and_line sal;
  1660.   sal = find_pc_line (pc, 0);
  1661.   *startptr = sal.pc;
  1662.   *endptr = sal.end;
  1663.   return sal.symtab != 0;
  1664. }
  1665.  
  1666. /* If P is of the form "operator[ \t]+..." where `...' is
  1667.    some legitimate operator text, return a pointer to the
  1668.    beginning of the substring of the operator text.
  1669.    Otherwise, return "".  */
  1670. static char *
  1671. operator_chars (p, end)
  1672.      char *p;
  1673.      char **end;
  1674. {
  1675.   *end = "";
  1676.   if (strncmp (p, "operator", 8))
  1677.     return *end;
  1678.   p += 8;
  1679.  
  1680.   /* Don't get faked out by `operator' being part of a longer
  1681.      identifier.  */
  1682.   if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')
  1683.       || *p == '_' || *p == '$' || *p == '\0')
  1684.     return *end;
  1685.  
  1686.   /* Allow some whitespace between `operator' and the operator symbol.  */
  1687.   while (*p == ' ' || *p == '\t')
  1688.     p++;
  1689.  
  1690.   switch (*p)
  1691.     {
  1692.     case '!':
  1693.     case '=':
  1694.     case '*':
  1695.     case '/':
  1696.     case '%':
  1697.     case '^':
  1698.       if (p[1] == '=')
  1699.     *end = p+2;
  1700.       else
  1701.     *end = p+1;
  1702.       return p;
  1703.     case '<':
  1704.     case '>':
  1705.     case '+':
  1706.     case '-':
  1707.     case '&':
  1708.     case '|':
  1709.       if (p[1] == '=' || p[1] == p[0])
  1710.     *end = p+2;
  1711.       else
  1712.     *end = p+1;
  1713.       return p;
  1714.     case '~':
  1715.     case ',':
  1716.       *end = p+1;
  1717.       return p;
  1718.     case '(':
  1719.       if (p[1] != ')')
  1720.     error ("`operator ()' must be specified without whitespace in `()'");
  1721.       *end = p+2;
  1722.       return p;
  1723.     case '?':
  1724.       if (p[1] != ':')
  1725.     error ("`operator ?:' must be specified without whitespace in `?:'");
  1726.       *end = p+2;
  1727.       return p;
  1728.     case '[':
  1729.       if (p[1] != ']')
  1730.     error ("`operator []' must be specified without whitespace in `[]'");
  1731.       *end = p+2;
  1732.       return p;
  1733.     default:
  1734.       error ("`operator %s' not supported", p);
  1735.       break;
  1736.     }
  1737.   *end = "";
  1738.   return *end;
  1739. }
  1740.  
  1741. /* Recursive helper function for decode_line_1.
  1742.  * Look for methods named NAME in type T.
  1743.  * Return number of matches.
  1744.  * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
  1745.  * These allocations seem to define "big enough":
  1746.  * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
  1747.  * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
  1748.  */
  1749.  
  1750. int
  1751. find_methods(t, name, physnames, sym_arr)
  1752.      struct type *t;
  1753.      char *name;
  1754.      char **physnames;
  1755.      struct symbol **sym_arr;
  1756. {
  1757.   int i1 = 0;
  1758.   int ibase;
  1759.   struct symbol *sym_class;
  1760.   char *class_name = type_name_no_tag (t);
  1761.   /* Ignore this class if it doesn't have a name.
  1762.      This prevents core dumps, but is just a workaround
  1763.      because we might not find the function in
  1764.      certain cases, such as
  1765.      struct D {virtual int f();}
  1766.      struct C : D {virtual int g();}
  1767.      (in this case g++ 1.35.1- does not put out a name
  1768.      for D as such, it defines type 19 (for example) in
  1769.      the same stab as C, and then does a
  1770.      .stabs "D:T19" and a .stabs "D:t19".
  1771.      Thus
  1772.      "break C::f" should not be looking for field f in
  1773.      the class named D, 
  1774.      but just for the field f in the baseclasses of C
  1775.      (no matter what their names).
  1776.      
  1777.      However, I don't know how to replace the code below
  1778.      that depends on knowing the name of D.  */
  1779.   if (class_name
  1780.       && (sym_class = lookup_symbol (class_name,
  1781.                      (struct block *)NULL,
  1782.                      STRUCT_NAMESPACE,
  1783.                      (int *)NULL,
  1784.                      (struct symtab **)NULL)))
  1785.     {
  1786.       int method_counter;
  1787.       t = SYMBOL_TYPE (sym_class);
  1788.       for (method_counter = TYPE_NFN_FIELDS (t) - 1;
  1789.        method_counter >= 0;
  1790.        --method_counter)
  1791.     {
  1792.       int field_counter;
  1793.       struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
  1794.  
  1795.       char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
  1796.       if (!strcmp (name, method_name))
  1797.         /* Find all the fields with that name.  */
  1798.         for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
  1799.          field_counter >= 0;
  1800.          --field_counter)
  1801.           {
  1802.         char *phys_name;
  1803.         if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, field_counter)) & TYPE_FLAG_STUB)
  1804.           check_stub_method (t, method_counter, field_counter);
  1805.         phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
  1806.         physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
  1807.         strcpy (physnames[i1], phys_name);
  1808.         sym_arr[i1] = lookup_symbol (phys_name,
  1809.                          SYMBOL_BLOCK_VALUE (sym_class),
  1810.                          VAR_NAMESPACE,
  1811.                          (int *) NULL,
  1812.                          (struct symtab **) NULL);
  1813.         if (sym_arr[i1]) i1++;
  1814.           }
  1815.     }
  1816.     }
  1817.   /* Only search baseclasses if there is no match yet,
  1818.    * since names in derived classes override those in baseclasses.
  1819.    */
  1820.   if (i1)
  1821.     return i1;
  1822.   for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
  1823.     i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
  1824.                physnames + i1, sym_arr + i1);
  1825.   return i1;
  1826. }
  1827.  
  1828. /* Parse a string that specifies a line number.
  1829.    Pass the address of a char * variable; that variable will be
  1830.    advanced over the characters actually parsed.
  1831.  
  1832.    The string can be:
  1833.  
  1834.    LINENUM -- that line number in current file.  PC returned is 0.
  1835.    FILE:LINENUM -- that line in that file.  PC returned is 0.
  1836.    FUNCTION -- line number of openbrace of that function.
  1837.       PC returned is the start of the function.
  1838.    VARIABLE -- line number of definition of that variable.
  1839.       PC returned is 0.
  1840.    FILE:FUNCTION -- likewise, but prefer functions in that file.
  1841.    *EXPR -- line in which address EXPR appears.
  1842.  
  1843.    FUNCTION may be an undebuggable function found in misc_function_vector.
  1844.  
  1845.    If the argument FUNFIRSTLINE is nonzero, we want the first line
  1846.    of real code inside a function when a function is specified.
  1847.  
  1848.    DEFAULT_SYMTAB specifies the file to use if none is specified.
  1849.    It defaults to current_source_symtab.
  1850.    DEFAULT_LINE specifies the line number to use for relative
  1851.    line numbers (that start with signs).  Defaults to current_source_line.
  1852.  
  1853.    Note that it is possible to return zero for the symtab
  1854.    if no file is validly specified.  Callers must check that.
  1855.    Also, the line number returned may be invalid.  */
  1856.  
  1857. struct symtabs_and_lines
  1858. decode_line_1 (argptr, funfirstline, default_symtab, default_line)
  1859.      char **argptr;
  1860.      int funfirstline;
  1861.      struct symtab *default_symtab;
  1862.      int default_line;
  1863. {
  1864.   struct symtabs_and_lines decode_line_2 ();
  1865.   struct symtabs_and_lines values;
  1866.   struct symtab_and_line val;
  1867.   register char *p, *p1;
  1868.   char *q, *q1;
  1869.   register struct symtab *s;
  1870.  
  1871.   register struct symbol *sym;
  1872.   /* The symtab that SYM was found in.  */
  1873.   struct symtab *sym_symtab;
  1874.  
  1875.   register CORE_ADDR pc;
  1876.   register int i;
  1877.   char *copy;
  1878.   struct symbol *sym_class;
  1879.   int i1;
  1880.   struct symbol **sym_arr;
  1881.   struct type *t;
  1882.   char **physnames;
  1883.   
  1884.   /* Defaults have defaults.  */
  1885.  
  1886.   if (default_symtab == 0)
  1887.     {
  1888.       default_symtab = current_source_symtab;
  1889.       default_line = current_source_line;
  1890.     }
  1891.  
  1892.   /* See if arg is *PC */
  1893.  
  1894.   if (**argptr == '*')
  1895.     {
  1896.       (*argptr)++;
  1897.       pc = parse_and_eval_address_1 (argptr);
  1898.       values.sals = (struct symtab_and_line *)
  1899.     xmalloc (sizeof (struct symtab_and_line));
  1900.       values.nelts = 1;
  1901.       values.sals[0] = find_pc_line (pc, 0);
  1902.       values.sals[0].pc = pc;
  1903.       return values;
  1904.     }
  1905.  
  1906.   /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
  1907.  
  1908.   s = 0;
  1909.  
  1910.   for (p = *argptr; *p; p++)
  1911.     {
  1912.       if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
  1913.     break;
  1914.     }
  1915.   while (p[0] == ' ' || p[0] == '\t') p++;
  1916.  
  1917.   q = operator_chars (*argptr, &q1);
  1918.   if (p[0] == ':')
  1919.     {
  1920.  
  1921.       /*  C++  */
  1922.       if (p[1] ==':')
  1923.     {
  1924.       /* Extract the class name.  */
  1925.       p1 = p;
  1926.       while (p != *argptr && p[-1] == ' ') --p;
  1927.       copy = (char *) alloca (p - *argptr + 1);
  1928.       bcopy (*argptr, copy, p - *argptr);
  1929.       copy[p - *argptr] = 0;
  1930.  
  1931.       /* Discard the class name from the arg.  */
  1932.       p = p1 + 2;
  1933.       while (*p == ' ' || *p == '\t') p++;
  1934.       *argptr = p;
  1935.  
  1936.       sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, 
  1937.                      (struct symtab **)NULL);
  1938.        
  1939.       if (sym_class &&
  1940.           (TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
  1941.            || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
  1942.         {
  1943.           /* Arg token is not digits => try it as a function name
  1944.          Find the next token (everything up to end or next whitespace). */
  1945.           p = *argptr;
  1946.           while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
  1947.           q = operator_chars (*argptr, &q1);
  1948.  
  1949.           copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
  1950.           if (q1 - q)
  1951.         {
  1952.           copy[0] = 'o';
  1953.           copy[1] = 'p';
  1954.           copy[2] = CPLUS_MARKER;
  1955.           bcopy (q, copy + 3, q1 - q);
  1956.           copy[3 + (q1 - q)] = '\0';
  1957.           p = q1;
  1958.         }
  1959.           else
  1960.         {
  1961.           bcopy (*argptr, copy, p - *argptr);
  1962.           copy[p - *argptr] = '\0';
  1963.         }
  1964.  
  1965.           /* no line number may be specified */
  1966.           while (*p == ' ' || *p == '\t') p++;
  1967.           *argptr = p;
  1968.  
  1969.           sym = 0;
  1970.           i1 = 0;        /*  counter for the symbol array */
  1971.           t = SYMBOL_TYPE (sym_class);
  1972.           sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
  1973.           physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
  1974.  
  1975.           if (destructor_name_p (copy, t))
  1976.         {
  1977.           /* destructors are a special case.  */
  1978.           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
  1979.           int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
  1980.           char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
  1981.           physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
  1982.           strcpy (physnames[i1], phys_name);
  1983.           sym_arr[i1] =
  1984.             lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
  1985.                    VAR_NAMESPACE, 0, (struct symtab **)NULL);
  1986.           if (sym_arr[i1]) i1++;
  1987.         }
  1988.           else
  1989.         i1 = find_methods (t, copy, physnames, sym_arr);
  1990.           if (i1 == 1)
  1991.         {
  1992.           /* There is exactly one field with that name.  */
  1993.           sym = sym_arr[0];
  1994.  
  1995.           if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
  1996.             {
  1997.               /* Arg is the name of a function */
  1998.               pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
  1999.               if (funfirstline)
  2000.             SKIP_PROLOGUE (pc);
  2001.               values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
  2002.               values.nelts = 1;
  2003.               values.sals[0] = find_pc_line (pc, 0);
  2004.               values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
  2005.             }
  2006.           else
  2007.             {
  2008.               values.nelts = 0;
  2009.             }
  2010.           return values;
  2011.         }
  2012.           if (i1 > 0)
  2013.         {
  2014.           /* There is more than one field with that name
  2015.              (overloaded).  Ask the user which one to use.  */
  2016.           return decode_line_2 (sym_arr, i1, funfirstline);
  2017.         }
  2018.           else
  2019.         {
  2020.           char *tmp;
  2021.  
  2022.           if (OPNAME_PREFIX_P (copy))
  2023.             {
  2024.               tmp = (char *)alloca (strlen (copy+3) + 9);
  2025.               strcpy (tmp, "operator ");
  2026.               strcat (tmp, copy+3);
  2027.             }
  2028.           else
  2029.             tmp = copy;
  2030.           error ("that class does not have any method named %s", tmp);
  2031.         }
  2032.         }
  2033.       else
  2034.         /* The quotes are important if copy is empty.  */
  2035.         error("No class, struct, or union named \"%s\"", copy );
  2036.     }
  2037.       /*  end of C++  */
  2038.  
  2039.  
  2040.       /* Extract the file name.  */
  2041.       p1 = p;
  2042.       while (p != *argptr && p[-1] == ' ') --p;
  2043.       copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
  2044.       if (q1 - q)
  2045.     {
  2046.       copy[0] = 'o';
  2047.       copy[1] = 'p';
  2048.       copy[2] = CPLUS_MARKER;
  2049.       bcopy (q, copy + 3, q1-q);
  2050.       copy[3 + (q1-q)] = 0;
  2051.       p = q1;
  2052.     }
  2053.       else
  2054.     {
  2055.       bcopy (*argptr, copy, p - *argptr);
  2056.       copy[p - *argptr] = 0;
  2057.     }
  2058.  
  2059.       /* Find that file's data.  */
  2060.       s = lookup_symtab (copy);
  2061.       if (s == 0)
  2062.     {
  2063.       if (symtab_list == 0 && partial_symtab_list == 0)
  2064.         error (no_symtab_msg);
  2065.       error ("No source file named %s.", copy);
  2066.     }
  2067.  
  2068.       /* Discard the file name from the arg.  */
  2069.       p = p1 + 1;
  2070.       while (*p == ' ' || *p == '\t') p++;
  2071.       *argptr = p;
  2072.     }
  2073.  
  2074.   /* S is specified file's symtab, or 0 if no file specified.
  2075.      arg no longer contains the file name.  */
  2076.  
  2077.   /* Check whether arg is all digits (and sign) */
  2078.  
  2079.   p = *argptr;
  2080.   if (*p == '-' || *p == '+') p++;
  2081.   while (*p >= '0' && *p <= '9')
  2082.     p++;
  2083.  
  2084.   if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
  2085.     {
  2086.       /* We found a token consisting of all digits -- at least one digit.  */
  2087.       enum sign {none, plus, minus} sign = none;
  2088.  
  2089.       /* This is where we need to make sure that we have good defaults.
  2090.      We must guarantee that this section of code is never executed
  2091.      when we are called with just a function name, since
  2092.      select_source_symtab calls us with such an argument  */
  2093.  
  2094.       if (s == 0 && default_symtab == 0)
  2095.     {
  2096.       select_source_symtab (0);
  2097.       default_symtab = current_source_symtab;
  2098.       default_line = current_source_line;
  2099.     }
  2100.  
  2101.       if (**argptr == '+')
  2102.     sign = plus, (*argptr)++;
  2103.       else if (**argptr == '-')
  2104.     sign = minus, (*argptr)++;
  2105.       val.line = atoi (*argptr);
  2106.       switch (sign)
  2107.     {
  2108.     case plus:
  2109.       if (p == *argptr)
  2110.         val.line = 5;
  2111.       if (s == 0)
  2112.         val.line = default_line + val.line;
  2113.       break;
  2114.     case minus:
  2115.       if (p == *argptr)
  2116.         val.line = 15;
  2117.       if (s == 0)
  2118.         val.line = default_line - val.line;
  2119.       else
  2120.         val.line = 1;
  2121.       break;
  2122.     case none:
  2123.       break;    /* No need to adjust val.line.  */
  2124.     }
  2125.  
  2126.       while (*p == ' ' || *p == '\t') p++;
  2127.       *argptr = p;
  2128.       if (s == 0)
  2129.     s = default_symtab;
  2130.       val.symtab = s;
  2131.       val.pc = 0;
  2132.       values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
  2133.       values.sals[0] = val;
  2134.       values.nelts = 1;
  2135.       return values;
  2136.     }
  2137.  
  2138.   /* Arg token is not digits => try it as a variable name
  2139.      Find the next token (everything up to end or next whitespace).  */
  2140.   p = *argptr;
  2141.   while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
  2142.   copy = (char *) alloca (p - *argptr + 1);
  2143.   bcopy (*argptr, copy, p - *argptr);
  2144.   copy[p - *argptr] = 0;
  2145.   while (*p == ' ' || *p == '\t') p++;
  2146.   *argptr = p;
  2147.  
  2148.   /* Look up that token as a variable.
  2149.      If file specified, use that file's per-file block to start with.  */
  2150.  
  2151.   sym = lookup_symbol (copy,
  2152.                (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
  2153.             : get_selected_block ()),
  2154.                VAR_NAMESPACE, 0, &sym_symtab);
  2155.  
  2156.   if (sym != NULL)
  2157.     {
  2158.       if (SYMBOL_CLASS (sym) == LOC_BLOCK)
  2159.     {
  2160.       /* Arg is the name of a function */
  2161.       pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
  2162.       if (funfirstline)
  2163.         SKIP_PROLOGUE (pc);
  2164.       val = find_pc_line (pc, 0);
  2165. #ifdef PROLOGUE_FIRSTLINE_OVERLAP
  2166.       /* Convex: no need to suppress code on first line, if any */
  2167.       val.pc = pc;
  2168. #else
  2169.       val.pc = (val.end && val.pc != pc) ? val.end : pc;
  2170. #endif
  2171.       values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
  2172.       values.sals[0] = val;
  2173.       values.nelts = 1;
  2174.       
  2175.       /* I think this is always the same as the line that
  2176.          we calculate above, but the general principle is
  2177.          "trust the symbols more than stuff like
  2178.          SKIP_PROLOGUE".  */
  2179.       if (SYMBOL_LINE (sym) != 0)
  2180.         values.sals[0].line = SYMBOL_LINE (sym);
  2181.       
  2182.       return values;
  2183.     }
  2184.       else if (SYMBOL_LINE (sym) != 0)
  2185.     {
  2186.       /* We know its line number.  */
  2187.       values.sals = (struct symtab_and_line *)
  2188.         xmalloc (sizeof (struct symtab_and_line));
  2189.       values.nelts = 1;
  2190.       bzero (&values.sals[0], sizeof (values.sals[0]));
  2191.       values.sals[0].symtab = sym_symtab;
  2192.       values.sals[0].line = SYMBOL_LINE (sym);
  2193.       return values;
  2194.     }
  2195.       else
  2196.     /* This can happen if it is compiled with a compiler which doesn't
  2197.        put out line numbers for variables.  */
  2198.     error ("Line number not known for symbol \"%s\"", copy);
  2199.     }
  2200.  
  2201.   if ((i = lookup_misc_func (copy)) >= 0)
  2202.     {
  2203.       val.symtab = 0;
  2204.       val.line = 0;
  2205.       val.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET;
  2206.       if (funfirstline)
  2207.     SKIP_PROLOGUE (val.pc);
  2208.       values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
  2209.       values.sals[0] = val;
  2210.       values.nelts = 1;
  2211.       return values;
  2212.     }
  2213.  
  2214.   if (symtab_list == 0 && partial_symtab_list == 0 && misc_function_count == 0)
  2215.     error (no_symtab_msg);
  2216.  
  2217.   error ("Function %s not defined.", copy);
  2218.   return values;    /* for lint */
  2219. }
  2220.  
  2221. struct symtabs_and_lines
  2222. decode_line_spec (string, funfirstline)
  2223.      char *string;
  2224.      int funfirstline;
  2225. {
  2226.   struct symtabs_and_lines sals;
  2227.   if (string == 0)
  2228.     error ("Empty line specification.");
  2229.   sals = decode_line_1 (&string, funfirstline,
  2230.             current_source_symtab, current_source_line);
  2231.   if (*string)
  2232.     error ("Junk at end of line specification: %s", string);
  2233.   return sals;
  2234. }
  2235.  
  2236. /* Given a list of NELTS symbols in sym_arr (with corresponding
  2237.    mangled names in physnames), return a list of lines to operate on
  2238.    (ask user if necessary).  */
  2239. struct symtabs_and_lines
  2240. decode_line_2 (sym_arr, nelts, funfirstline)
  2241.      struct symbol *sym_arr[];
  2242.      int nelts;
  2243.      int funfirstline;
  2244. {
  2245.   struct symtabs_and_lines values, return_values;
  2246.   register CORE_ADDR pc;
  2247.   char *args, *arg1, *command_line_input ();
  2248.   int i;
  2249.   char *prompt;
  2250.  
  2251.   values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
  2252.   return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
  2253.  
  2254.   i = 0;
  2255.   printf("[0] cancel\n[1] all\n");
  2256.   while (i < nelts)
  2257.     {
  2258.       if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
  2259.     {
  2260.       /* Arg is the name of a function */
  2261.       pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i])) 
  2262.            + FUNCTION_START_OFFSET;
  2263.       if (funfirstline)
  2264.         SKIP_PROLOGUE (pc);
  2265.       values.sals[i] = find_pc_line (pc, 0);
  2266.       values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
  2267.                    values.sals[i].end                      :  pc;
  2268.       printf("[%d] file:%s; line number:%d\n",
  2269.          (i+2), values.sals[i].symtab->filename, values.sals[i].line);
  2270.     }
  2271.       else printf ("?HERE\n");
  2272.       i++;
  2273.     }
  2274.   
  2275.   if ((prompt = getenv ("PS2")) == NULL)
  2276.     {
  2277.       prompt = ">";
  2278.     }
  2279.   printf("%s ",prompt);
  2280.   fflush(stdout);
  2281.  
  2282.   args = command_line_input (0, 0);
  2283.   
  2284.   if (args == 0)
  2285.     error_no_arg ("one or more choice numbers");
  2286.  
  2287.   i = 0;
  2288.   while (*args)
  2289.     {
  2290.       int num;
  2291.  
  2292.       arg1 = args;
  2293.       while (*arg1 >= '0' && *arg1 <= '9') arg1++;
  2294.       if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
  2295.     error ("Arguments must be choice numbers.");
  2296.  
  2297.       num = atoi (args);
  2298.  
  2299.       if (num == 0)
  2300.     error ("cancelled");
  2301.       else if (num == 1)
  2302.     {
  2303.       bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
  2304.       return_values.nelts = nelts;
  2305.       return return_values;
  2306.     }
  2307.  
  2308.       if (num > nelts + 2)
  2309.     {
  2310.       printf ("No choice number %d.\n", num);
  2311.     }
  2312.       else
  2313.     {
  2314.       num -= 2;
  2315.       if (values.sals[num].pc)
  2316.         {
  2317.           return_values.sals[i++] = values.sals[num];
  2318.           values.sals[num].pc = 0;
  2319.         }
  2320.       else
  2321.         {
  2322.           printf ("duplicate request for %d ignored.\n", num);
  2323.         }
  2324.     }
  2325.  
  2326.       args = arg1;
  2327.       while (*args == ' ' || *args == '\t') args++;
  2328.     }
  2329.   return_values.nelts = i;
  2330.   return return_values;
  2331. }
  2332.  
  2333. /* Return the index of misc function named NAME.  */
  2334.  
  2335. int
  2336. lookup_misc_func (name)
  2337.      register char *name;
  2338. {
  2339.   register int i;
  2340.  
  2341.   for (i = 0; i < misc_function_count; i++)
  2342.     if (!lisp_strcmp (misc_function_vector[i].name, name))
  2343.       return i;
  2344.   return -1;        /* not found */
  2345. }
  2346.  
  2347. /* Slave routine for sources_info.  Force line breaks at ,'s.
  2348.    NAME is the name to print and *FIRST is nonzero if this is the first
  2349.    name printed.  Set *FIRST to zero.  */
  2350. static void
  2351. output_source_filename (name, first)
  2352.      char *name;
  2353.      int *first;
  2354. {
  2355.   static int column;
  2356.   /* Table of files printed so far.  Since a single source file can
  2357.      result in several partial symbol tables, we need to avoid printing
  2358.      it more than once.  Note: if some of the psymtabs are read in and
  2359.      some are not, it gets printed both under "Source files for which
  2360.      symbols have been read" and "Source files for which symbols will
  2361.      be read in on demand".  I consider this a reasonable way to deal
  2362.      with the situation.  I'm not sure whether this can also happen for
  2363.      symtabs; it doesn't hurt to check.  */
  2364.   static char **tab = NULL;
  2365.   /* Allocated size of tab in elements.
  2366.      Start with one 256-byte block (when using GNU malloc.c).
  2367.      24 is the malloc overhead when range checking is in effect.  */
  2368.   static int tab_alloc_size = (256 - 24) / sizeof (char *);
  2369.   /* Current size of tab in elements.  */
  2370.   static int tab_cur_size;
  2371.  
  2372.   char **p;
  2373.  
  2374.   if (*first)
  2375.     {
  2376.       if (tab == NULL)
  2377.     tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
  2378.       tab_cur_size = 0;
  2379.     }
  2380.  
  2381.   /* Is NAME in tab?  */
  2382.   for (p = tab; p < tab + tab_cur_size; p++)
  2383.     if (strcmp (*p, name) == 0)
  2384.       /* Yes; don't print it again.  */
  2385.       return;
  2386.   /* No; add it to tab.  */
  2387.   if (tab_cur_size == tab_alloc_size)
  2388.     {
  2389.       tab_alloc_size *= 2;
  2390.       tab = (char **) xrealloc (tab, tab_alloc_size * sizeof (*tab));
  2391.     }
  2392.   tab[tab_cur_size++] = name;
  2393.  
  2394.   if (*first)
  2395.     {
  2396.       column = 0;
  2397.       *first = 0;
  2398.     }
  2399.   else
  2400.     {
  2401.       printf_filtered (",");
  2402.       column++;
  2403.     }
  2404.  
  2405.   if (column != 0 && column + strlen (name) >= 70)
  2406.     {
  2407.       printf_filtered ("\n");
  2408.       column = 0;
  2409.     }
  2410.   else if (column != 0)
  2411.     {
  2412.       printf_filtered (" ");
  2413.       column++;
  2414.     }
  2415.   fputs_filtered (name, stdout);
  2416.   column += strlen (name);
  2417. }  
  2418.  
  2419. static void
  2420. sources_info ()
  2421. {
  2422.   register struct symtab *s;
  2423.   register struct partial_symtab *ps;
  2424.   int first;
  2425.   
  2426.   if (symtab_list == 0 && partial_symtab_list == 0)
  2427.     {
  2428.       printf (no_symtab_msg);
  2429.       return;
  2430.     }
  2431.   
  2432.   printf_filtered ("Source files for which symbols have been read in:\n\n");
  2433.  
  2434.   first = 1;
  2435.   for (s = symtab_list; s; s = s->next)
  2436.     output_source_filename (s->filename, &first);
  2437.   printf_filtered ("\n\n");
  2438.   
  2439.   printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
  2440.  
  2441.   first = 1;
  2442.   for (ps = partial_symtab_list; ps; ps = ps->next)
  2443.     if (!ps->readin)
  2444.       output_source_filename (ps->filename, &first);
  2445.   printf_filtered ("\n");
  2446. }
  2447.  
  2448. /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
  2449.    If CLASS is zero, list all symbols except functions and type names.
  2450.    If CLASS is 1, list only functions.
  2451.    If CLASS is 2, list only type names.
  2452.    If CLASS is 3, list only method names.
  2453.  
  2454.    BPT is non-zero if we should set a breakpoint at the functions
  2455.    we find.  */
  2456.  
  2457. static void
  2458. list_symbols (regexp, class, bpt)
  2459.      char *regexp;
  2460.      int class;
  2461.      int bpt;
  2462. {
  2463.   register struct symtab *s;
  2464.   register struct partial_symtab *ps;
  2465.   register struct blockvector *bv;
  2466.   struct blockvector *prev_bv = 0;
  2467.   register struct block *b;
  2468.   register int i, j;
  2469.   register struct symbol *sym;
  2470.   struct partial_symbol *psym;
  2471.   char *val;
  2472.   static char *classnames[]
  2473.     = {"variable", "function", "type", "method"};
  2474.   int found_in_file = 0;
  2475.   int found_misc = 0;
  2476.   static enum misc_function_type types[]
  2477.     = {mf_data, mf_text, mf_abs, mf_unknown};
  2478.   static enum misc_function_type types2[]
  2479.     = {mf_bss,  mf_text, mf_abs, mf_unknown};
  2480.   enum misc_function_type ourtype = types[class];
  2481.   enum misc_function_type ourtype2 = types2[class];
  2482.  
  2483.   if (regexp)
  2484.     if (0 != (val = re_comp (regexp)))
  2485.       error ("Invalid regexp (%s): %s", val, regexp);
  2486.  
  2487.   /* Search through the partial_symtab_list *first* for all symbols
  2488.      matching the regexp.  That way we don't have to reproduce all of
  2489.      the machinery below. */
  2490.   for (ps = partial_symtab_list; ps; ps = ps->next)
  2491.     {
  2492.       struct partial_symbol *bound, *gbound, *sbound;
  2493.       int keep_going = 1;
  2494.  
  2495.       if (ps->readin) continue;
  2496.       
  2497.       gbound = global_psymbols.list + ps->globals_offset + ps->n_global_syms;
  2498.       sbound = static_psymbols.list + ps->statics_offset + ps->n_static_syms;
  2499.       bound = gbound;
  2500.  
  2501.       /* Go through all of the symbols stored in a partial
  2502.      symtab in one loop. */
  2503.       psym = global_psymbols.list + ps->globals_offset;
  2504.       while (keep_going)
  2505.     {
  2506.       if (psym >= bound)
  2507.         {
  2508.           if (bound == gbound && ps->n_static_syms != 0)
  2509.         {
  2510.           psym = static_psymbols.list + ps->statics_offset;
  2511.           bound = sbound;
  2512.         }
  2513.           else
  2514.         keep_going = 0;
  2515.           continue;
  2516.         }
  2517.       else
  2518.         {
  2519.           QUIT;
  2520.  
  2521.           /* If it would match (logic taken from loop below)
  2522.          load the file and go on to the next one */
  2523.           if ((regexp == 0 || re_exec (SYMBOL_NAME (psym)))
  2524.           && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
  2525.                   && SYMBOL_CLASS (psym) != LOC_BLOCK)
  2526.               || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
  2527.               || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
  2528.               || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
  2529.         {
  2530.           (void) PSYMTAB_TO_SYMTAB(ps);
  2531.           keep_going = 0;
  2532.         }
  2533.         }
  2534.       psym++;
  2535.     }
  2536.     }
  2537.  
  2538.   /* Here, we search through the misc function vector for functions that
  2539.      match, and call find_pc_symtab on them to force their symbols to
  2540.      be read.  The symbol will then be found during the scan of symtabs
  2541.      below.  If find_pc_symtab fails, set found_misc so that we will
  2542.      rescan to print any matching symbols without debug info.  */
  2543.  
  2544.   if (class == 1) {
  2545.     for (i = 0; i < misc_function_count; i++) {
  2546.       if (misc_function_vector[i].type != ourtype
  2547.        && misc_function_vector[i].type != ourtype2)
  2548.     continue;
  2549.       if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
  2550.       if (0 == find_pc_symtab (misc_function_vector[i].address))
  2551.         found_misc = 1;
  2552.       }
  2553.     }
  2554.   }
  2555.  
  2556.   /* Printout here so as to get after the "Reading in symbols"
  2557.      messages which will be generated above.  */
  2558.   if (!bpt)
  2559.     printf_filtered (regexp
  2560.       ? "All %ss matching regular expression \"%s\":\n"
  2561.       : "All defined %ss:\n",
  2562.       classnames[class],
  2563.       regexp);
  2564.  
  2565.   for (s = symtab_list; s; s = s->next)
  2566.     {
  2567.       found_in_file = 0;
  2568.       bv = BLOCKVECTOR (s);
  2569.       /* Often many files share a blockvector.
  2570.      Scan each blockvector only once so that
  2571.      we don't get every symbol many times.
  2572.      It happens that the first symtab in the list
  2573.      for any given blockvector is the main file.  */
  2574.       if (bv != prev_bv)
  2575.     for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
  2576.       {
  2577.         b = BLOCKVECTOR_BLOCK (bv, i);
  2578.         /* Skip the sort if this block is always sorted.  */
  2579.         if (!BLOCK_SHOULD_SORT (b))
  2580.           sort_block_syms (b);
  2581.         for (j = 0; j < BLOCK_NSYMS (b); j++)
  2582.           {
  2583.         QUIT;
  2584.         sym = BLOCK_SYM (b, j);
  2585.         if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
  2586.             && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
  2587.                     && SYMBOL_CLASS (sym) != LOC_BLOCK)
  2588.             || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
  2589.             || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  2590.             || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
  2591.           {
  2592.             if (bpt)
  2593.               {
  2594.             /* Set a breakpoint here, if it's a function */
  2595.             if (class == 1)
  2596.               break_command (SYMBOL_NAME(sym), 0);
  2597.               }
  2598.             else if (!found_in_file)
  2599.               {
  2600.             fputs_filtered ("\nFile ", stdout);
  2601.             fputs_filtered (s->filename, stdout);
  2602.             fputs_filtered (":\n", stdout);
  2603.               }
  2604.             found_in_file = 1;
  2605.  
  2606.             if (class != 2 && i == STATIC_BLOCK)
  2607.               printf_filtered ("static ");
  2608.  
  2609.             /* Typedef that is not a C++ class */
  2610.             if (class == 2
  2611.             && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
  2612.                typedef_print (SYMBOL_TYPE(sym), sym, stdout);
  2613.             /* variable, func, or typedef-that-is-c++-class */
  2614.             else if (class < 2 || 
  2615.                  (class == 2 && 
  2616.                 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
  2617.               {
  2618.              type_print (SYMBOL_TYPE (sym),
  2619.                      (SYMBOL_CLASS (sym) == LOC_TYPEDEF
  2620.                       ? "" : SYMBOL_NAME (sym)),
  2621.                      stdout, 0);
  2622.              
  2623.              printf_filtered (";\n");
  2624.               }
  2625.             else
  2626.               {
  2627. # if 0
  2628.             char buf[1024];
  2629.             type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0); 
  2630.             type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0); 
  2631.             sprintf (buf, " %s::", type_name_no_tag (t));
  2632.             type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
  2633. # endif
  2634.               }
  2635.           }
  2636.           }
  2637.       }
  2638.       prev_bv = bv;
  2639.     }
  2640.  
  2641.  
  2642.   /* If there are no eyes, avoid all contact.  I mean, if there are
  2643.      no debug symbols, then print directly from the misc_function_vector.  */
  2644.  
  2645.   if (found_misc || class != 1) {
  2646.     found_in_file = 0;
  2647.     for (i = 0; i < misc_function_count; i++) {
  2648.       if (misc_function_vector[i].type != ourtype
  2649.        && misc_function_vector[i].type != ourtype2)
  2650.     continue;
  2651.       if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
  2652.     /* Functions:  Look up by address. */
  2653.     if (class == 1)
  2654.       if (0 != find_pc_symtab (misc_function_vector[i].address))
  2655.         continue;
  2656.     /* Variables/Absolutes:  Look up by name */
  2657.     if (0 != lookup_symbol (misc_function_vector[i].name, 
  2658.         (struct block *)0, VAR_NAMESPACE, 0, (struct symtab **)0))
  2659.       continue;
  2660.     if (!found_in_file) {
  2661.       printf_filtered ("\nNon-debugging symbols:\n");
  2662.       found_in_file = 1;
  2663.     }
  2664.     printf_filtered ("    %08x  %s\n",
  2665.           misc_function_vector[i].address,
  2666.           misc_function_vector[i].name);
  2667.       }
  2668.     }
  2669.   }
  2670. }
  2671.  
  2672. static void
  2673. variables_info (regexp)
  2674.      char *regexp;
  2675. {
  2676.   list_symbols (regexp, 0, 0);
  2677. }
  2678.  
  2679. static void
  2680. functions_info (regexp)
  2681.      char *regexp;
  2682. {
  2683.   list_symbols (regexp, 1, 0);
  2684. }
  2685.  
  2686. static void
  2687. types_info (regexp)
  2688.      char *regexp;
  2689. {
  2690.   list_symbols (regexp, 2, 0);
  2691. }
  2692.  
  2693. #if 0
  2694. /* Tiemann says: "info methods was never implemented."  */
  2695. static void
  2696. methods_info (regexp)
  2697.      char *regexp;
  2698. {
  2699.   list_symbols (regexp, 3, 0);
  2700. }
  2701. #endif /* 0 */
  2702.  
  2703. /* Breakpoint all functions matching regular expression. */
  2704. static void
  2705. rbreak_command (regexp)
  2706.      char *regexp;
  2707. {
  2708.   list_symbols (regexp, 1, 1);
  2709. }
  2710.  
  2711. /* Helper function to initialize the standard scalar types.  */
  2712.  
  2713. struct type *
  2714. init_type (code, length, uns, name)
  2715.      enum type_code code;
  2716.      int length, uns;
  2717.      char *name;
  2718. {
  2719.   register struct type *type;
  2720.  
  2721.   type = (struct type *) xmalloc (sizeof (struct type));
  2722.   bzero (type, sizeof *type);
  2723.   TYPE_MAIN_VARIANT (type) = type;
  2724.   TYPE_CODE (type) = code;
  2725.   TYPE_LENGTH (type) = length;
  2726.   TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0;
  2727.   TYPE_FLAGS (type) |= TYPE_FLAG_PERM;
  2728.   TYPE_NFIELDS (type) = 0;
  2729.   TYPE_NAME (type) = name;
  2730.  
  2731.   /* C++ fancies.  */
  2732.   TYPE_NFN_FIELDS (type) = 0;
  2733.   TYPE_N_BASECLASSES (type) = 0;
  2734.   return type;
  2735. }
  2736.  
  2737. /* Return Nonzero if block a is lexically nested within block b,
  2738.    or if a and b have the same pc range.
  2739.    Return zero otherwise. */
  2740. int
  2741. contained_in (a, b)
  2742.      struct block *a, *b;
  2743. {
  2744.   if (!a || !b)
  2745.     return 0;
  2746.   return BLOCK_START (a) >= BLOCK_START (b)
  2747.       && BLOCK_END (a)   <= BLOCK_END (b);
  2748. }
  2749.  
  2750.  
  2751. /* Helper routine for make_symbol_completion_list.  */
  2752.  
  2753. int return_val_size, return_val_index;
  2754. char **return_val;
  2755.  
  2756. void
  2757. completion_list_add_symbol (symname)
  2758.      char *symname;
  2759. {
  2760.   if (return_val_index + 3 > return_val_size)
  2761.     return_val =
  2762.       (char **)xrealloc (return_val,
  2763.              (return_val_size *= 2) * sizeof (char *));
  2764.   
  2765.   return_val[return_val_index] =
  2766.     (char *)xmalloc (1 + strlen (symname));
  2767.   
  2768.   strcpy (return_val[return_val_index], symname);
  2769.   
  2770.   return_val[++return_val_index] = (char *)NULL;
  2771. }
  2772.  
  2773. /* Return a NULL terminated array of all symbols (regardless of class) which
  2774.    begin by matching TEXT.  If the answer is no symbols, then the return value
  2775.    is an array which contains only a NULL pointer.
  2776.  
  2777.    Problem: All of the symbols have to be copied because readline
  2778.    frees them.  I'm not going to worry about this; hopefully there
  2779.    won't be that many.  */
  2780.  
  2781. char **
  2782. make_symbol_completion_list (text)
  2783.   char *text;
  2784. {
  2785.   register struct symtab *s;
  2786.   register struct partial_symtab *ps;
  2787.   register struct block *b, *surrounding_static_block = 0;
  2788.   extern struct block *get_selected_block ();
  2789.   register int i, j;
  2790.   struct partial_symbol *psym;
  2791.  
  2792.   int text_len = strlen (text);
  2793.   return_val_size = 100;
  2794.   return_val_index = 0;
  2795.   return_val =
  2796.     (char **)xmalloc ((1 + return_val_size) *sizeof (char *));
  2797.   return_val[0] = (char *)NULL;
  2798.  
  2799.   /* Look through the partial symtabs for all symbols which begin
  2800.      by matching TEXT.  Add each one that you find to the list.  */
  2801.  
  2802.   for (ps = partial_symtab_list; ps; ps = ps->next)
  2803.     {
  2804.       /* If the psymtab's been read in we'll get it when we search
  2805.      through the blockvector.  */
  2806.       if (ps->readin) continue;
  2807.  
  2808.       for (psym = global_psymbols.list + ps->globals_offset;
  2809.        psym < (global_psymbols.list + ps->globals_offset
  2810.            + ps->n_global_syms);
  2811.        psym++)
  2812.     {
  2813.       QUIT;            /* If interrupted, then quit. */
  2814.       if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
  2815.         completion_list_add_symbol (SYMBOL_NAME (psym));
  2816.     }
  2817.       
  2818.       for (psym = static_psymbols.list + ps->statics_offset;
  2819.        psym < (static_psymbols.list + ps->statics_offset
  2820.            + ps->n_static_syms);
  2821.        psym++)
  2822.     {
  2823.       QUIT;
  2824.       if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
  2825.         completion_list_add_symbol (SYMBOL_NAME (psym));
  2826.     }
  2827.     }
  2828.  
  2829.   /* At this point scan through the misc function vector and add each
  2830.      symbol you find to the list.  Eventually we want to ignore
  2831.      anything that isn't a text symbol (everything else will be
  2832.      handled by the psymtab code above).  */
  2833.  
  2834.   for (i = 0; i < misc_function_count; i++)
  2835.     if (!strncmp (text, misc_function_vector[i].name, text_len))
  2836.       completion_list_add_symbol (misc_function_vector[i].name);
  2837.  
  2838.   /* Search upwards from currently selected frame (so that we can
  2839.      complete on local vars.  */
  2840.   for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
  2841.     {
  2842.       if (!BLOCK_SUPERBLOCK (b))
  2843.     surrounding_static_block = b; /* For elmin of dups */
  2844.       
  2845.       /* Also catch fields of types defined in this places which
  2846.      match our text string.  Only complete on types visible
  2847.      from current context.  */
  2848.       for (i = 0; i < BLOCK_NSYMS (b); i++)
  2849.     {
  2850.       register struct symbol *sym = BLOCK_SYM (b, i);
  2851.       
  2852.       if (!strncmp (SYMBOL_NAME (sym), text, text_len))
  2853.         completion_list_add_symbol (SYMBOL_NAME (sym));
  2854.  
  2855.       if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  2856.         {
  2857.           struct type *t = SYMBOL_TYPE (sym);
  2858.           enum type_code c = TYPE_CODE (t);
  2859.  
  2860.           if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
  2861.         for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
  2862.           if (TYPE_FIELD_NAME (t, j) &&
  2863.               !strncmp (TYPE_FIELD_NAME (t, j), text, text_len))
  2864.             completion_list_add_symbol (TYPE_FIELD_NAME (t, j));
  2865.         }
  2866.     }
  2867.     }
  2868.  
  2869.   /* Go through the symtabs and check the externs and statics for
  2870.      symbols which match.  */
  2871.  
  2872.   for (s = symtab_list; s; s = s->next)
  2873.     {
  2874.       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
  2875.       
  2876.       for (i = 0; i < BLOCK_NSYMS (b); i++)
  2877.     if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
  2878.       completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
  2879.     }
  2880.  
  2881.   for (s = symtab_list; s; s = s->next)
  2882.     {
  2883.       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
  2884.  
  2885.       /* Don't do this block twice.  */
  2886.       if (b == surrounding_static_block) continue;
  2887.       
  2888.       for (i = 0; i < BLOCK_NSYMS (b); i++)
  2889.     if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
  2890.       completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
  2891.     }
  2892.  
  2893.   return (return_val);
  2894. }
  2895.  
  2896. #if 0
  2897. /* Add the type of the symbol sym to the type of the current
  2898.    function whose block we are in (assumed).  The type of
  2899.    this current function is contained in *TYPE.
  2900.    
  2901.    This basically works as follows:  When we find a function
  2902.    symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
  2903.    a pointer to its type in the global in_function_type.  Every 
  2904.    time we come across a parameter symbol ('p' in its name), then
  2905.    this procedure adds the name and type of that parameter
  2906.    to the function type pointed to by *TYPE.  (Which should correspond
  2907.    to in_function_type if it was called correctly).
  2908.  
  2909.    Note that since we are modifying a type, the result of 
  2910.    lookup_function_type() should be bcopy()ed before calling
  2911.    this.  When not in strict typing mode, the expression
  2912.    evaluator can choose to ignore this.
  2913.  
  2914.    Assumption:  All of a function's parameter symbols will
  2915.    appear before another function symbol is found.  The parameters 
  2916.    appear in the same order in the argument list as they do in the
  2917.    symbol table. */
  2918.  
  2919. void
  2920. add_param_to_type (type,sym)
  2921.    struct type **type;
  2922.    struct symbol *sym;
  2923. {
  2924.    int num = ++(TYPE_NFIELDS(*type));
  2925.  
  2926.    if(TYPE_NFIELDS(*type)-1)
  2927.       TYPE_FIELDS(*type) = 
  2928.      (struct field *)xrealloc((char *)(TYPE_FIELDS(*type)),
  2929.                   num*sizeof(struct field));
  2930.    else
  2931.       TYPE_FIELDS(*type) =
  2932.      (struct field *)xmalloc(num*sizeof(struct field));
  2933.    
  2934.    TYPE_FIELD_BITPOS(*type,num-1) = num-1;
  2935.    TYPE_FIELD_BITSIZE(*type,num-1) = 0;
  2936.    TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
  2937.    TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
  2938. }
  2939. #endif 
  2940.  
  2941. void
  2942. _initialize_symtab ()
  2943. {
  2944.   add_info ("variables", variables_info,
  2945.         "All global and static variable names, or those matching REGEXP.");
  2946.   add_info ("functions", functions_info,
  2947.         "All function names, or those matching REGEXP.");
  2948.  
  2949.   /* FIXME:  This command has at least the following problems:
  2950.      1.  It prints builtin types (in a very strange and confusing fashion).
  2951.      2.  It doesn't print right, e.g. with
  2952.          typedef struct foo *FOO
  2953.      type_print prints "FOO" when we want to make it (in this situation)
  2954.      print "struct foo *".
  2955.      I also think "ptype" or "whatis" is more likely to be useful (but if
  2956.      there is much disagreement "info types" can be fixed).  */
  2957.   add_info ("types", types_info,
  2958.         "All types names, or those matching REGEXP.");
  2959.  
  2960. #if 0
  2961.   add_info ("methods", methods_info,
  2962.         "All method names, or those matching REGEXP::REGEXP.\n\
  2963. If the class qualifier is ommited, it is assumed to be the current scope.\n\
  2964. If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
  2965. are listed.");
  2966. #endif
  2967.   add_info ("sources", sources_info,
  2968.         "Source files in the program.");
  2969.  
  2970.   add_com ("rbreak", no_class, rbreak_command,
  2971.         "Set a breakpoint for all functions matching REGEXP.");
  2972.  
  2973.   /* Initialize the one built-in type that isn't language dependent... */
  2974.   builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>");
  2975. }
  2976.